Created
September 12, 2011 10:10
-
-
Save premasagar/1210964 to your computer and use it in GitHub Desktop.
Detect search parameter in window location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hasSearchParam(param, value){ | |
var pattern = "^[\?&]" + param + | |
(typeof value === "undefined" ? "($|[=&])" : "=" + value + "($|&)"); | |
return (new RegExp(pattern)).test(window.location.search); | |
} | |
// e.g. hasSearchParam("debug") on http://example.com?debug | |
// e.g. hasSearchParam("foo", "bar") on http://example.com?foo=bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment