Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created March 9, 2015 14:17
Show Gist options
  • Save justinobney/3a4b9032bee0938c4b3d to your computer and use it in GitHub Desktop.
Save justinobney/3a4b9032bee0938c4b3d to your computer and use it in GitHub Desktop.
get querystring params
function gup(name, url, defaultValue) {
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]) || defaultValue;
}
var id = gup('id', document.location.toString(), '50');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment