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
Community
  • 1
  • 1
user1898657
  • 495
  • 2
  • 5
  • 14
  • This issue is covered in detail [here](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values). – Giacomo1968 Jan 22 '13 at 16:52
  • 2
    "everything after the question mark" and querystring are two different things. – Christophe Jan 22 '13 at 16:53
  • See also [JavaScript query string](http://stackoverflow.com/questions/647259/javascript-query-string). –  Jul 31 '13 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. – Keyslinger Mar 14 '16 at 21:43

4 Answers4

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.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
4
var querystring=window.location.search.substring(1);
kennebec
  • 102,654
  • 32
  • 106
  • 127
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("?");
Christophe
  • 27,383
  • 28
  • 97
  • 140
1

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

Alnitak
  • 334,560
  • 70
  • 407
  • 495