Skip to content

Instantly share code, notes, and snippets.

@premasagar
Created September 12, 2011 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save premasagar/1210964 to your computer and use it in GitHub Desktop.
Save premasagar/1210964 to your computer and use it in GitHub Desktop.
Detect search parameter in window location
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