views:

74

answers:

4

Is it possible using jquery (or just javascript) to check for the existence of a query string on the URL?

+6  A: 

Yes, the location object has a property search that contains the query string.

alert(window.location.search);
Felix Kling
A: 

document.location contains information about the URL, and document.location.search contains the query string, e.g. ?foo=bar&spam=eggs. As for testing its presence, how about:

if(document.location.search.length) {
    // query string exists
} else {
    // no query string exists
}

No jQuery required :o

Matchu
A: 

I would think you could use the javascript match operator.

var url = window.location.search;
if (url.match("your string").length > 0) {
}
Neil
A: 

Check out http://rixi.us/post/791257125/get-and-server-free-dynamic-contet

a method to extract any query string parameters
Use::

if (_GET['key']) {
  var key = _GET['key']
}
Rixius