13

Possible Duplicate:
obtaining querystring from current url in javascript?

I was to get everything after the question mark in the url. Ive seen a way to do it that does not require a function but cannot find it for the life of me.

url

fsdhfbsdfj/index.html?hello

get

hello
3
  • 2
    "everything after the question mark" and querystring are two different things. Commented Jan 22, 2013 at 16:53
  • See also JavaScript query string. Commented Jul 31, 2013 at 23:11
  • 2
    This is not a duplicate! Every other question concerned with accessing the query string also includes the step of parsing it. This one gave me the much simpler answer to the intermediate question of simply getting it unparsed. Commented Mar 14, 2016 at 21:43

4 Answers 4

31

Use

var query = window.location.search;

If you want to get rid of the starting "?", use

var query = window.location.search.slice(1);

The properties of the location object are described here.

Sign up to request clarification or add additional context in comments.

Comments

4
var querystring=window.location.search.substring(1);

Comments

2

Your title says "get querystring", but your question says "get everything after the question mark" which is something different and can include both a querystring and a hash.

I assume that when you say "the" url you are talking about the current Web page.

To get the querystring:

window.location.search

To get everything after the first ?:

window.location.href.split("?").slice(1).join("?");

Comments

1

You can find the query string in window.location.search

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.