Reputation: 10552
Is it possible using jquery (or just javascript) to check for the existence of a query string on the URL?
Upvotes: 28
Views: 54299
Reputation: 2303
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']
}
Upvotes: -3
Reputation: 274
I would think you could use the javascript match operator.
var url = window.location.search;
if (url.match("your string").length > 0) {
}
Upvotes: 5
Reputation: 85862
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
Upvotes: 32
Reputation: 817128
Yes, the location
object has a property search
that contains the query string.
alert(window.location.search);
Upvotes: 40