Skip to content

Instantly share code, notes, and snippets.

@leongaban
Created March 3, 2016 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leongaban/ccd00db5e034d8078893 to your computer and use it in GitHub Desktop.
Save leongaban/ccd00db5e034d8078893 to your computer and use it in GitHub Desktop.
Get variable from URL param
// For url with ?search=param
// http://stackoverflow.com/a/979997/168738
function gurlp( name, url ) {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
return results == null ? null : results[1];
}
var param = gurlp('search', window.location.href);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment