Skip to content

Instantly share code, notes, and snippets.

@waaronking
Created October 30, 2014 17:11
Show Gist options
  • Save waaronking/7531b83ad8000edf0f4d to your computer and use it in GitHub Desktop.
Save waaronking/7531b83ad8000edf0f4d to your computer and use it in GitHub Desktop.
getURLParameters
//Works fairly well
/* Get URL parameters */
function getUrlParam(key) {
var params = [], pair;
var pairs = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
if (key) {
return decodeURIComponent((new RegExp('[?|&]' + key + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
} else {
//split the key/value pairs
for(var i=0; i<pairs.length; i++){
pair = pairs[i].split('=');
params.push(pair[0]);
params[pair[0]] = pair[1];
}
return params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment