Skip to content

Instantly share code, notes, and snippets.

@cookpete
Last active December 13, 2015 16:49
Show Gist options
  • Save cookpete/4943243 to your computer and use it in GitHub Desktop.
Save cookpete/4943243 to your computer and use it in GitHub Desktop.
Create a global object containing key/value pairs of URL parameters
function parseParams(string){
var obj = {};
string.replace(/[?&]?([^=]+)=([^&]*)/g, function(m,k,v) { obj[k] = v; });
return obj;
}
var url = parseParams(location.search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment