Skip to content

Instantly share code, notes, and snippets.

@fabriceleal
Last active December 23, 2015 08:39
Show Gist options
  • Save fabriceleal/6609675 to your computer and use it in GitHub Desktop.
Save fabriceleal/6609675 to your computer and use it in GitHub Desktop.
Get query parameters
function getParams() {
var parameters = location.search.substring(1).split('&'); // drop initial '?' and get array of 'key=value'
var obj = {};
for(var i=0; i < parameters.length; ++i){
// 0 with the key, 1 with the value
var keyvalue = parameters[i].split('=');
// this won't work well when we try to pass jsons as parameters.
obj[ decodeURIComponent(keyvalue[0]) ] = decodeURIComponent(keyvalue[1]);
}
return obj;
}
@fabriceleal
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment