Skip to content

Instantly share code, notes, and snippets.

@davidroyer
Created January 26, 2019 01:52
Show Gist options
  • Save davidroyer/2b16bf32bcec731d3b6e7b8097fa4703 to your computer and use it in GitHub Desktop.
Save davidroyer/2b16bf32bcec731d3b6e7b8097fa4703 to your computer and use it in GitHub Desktop.
var getParams = function (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params;
};
/* TO USE IT:
getParams(window.location.href)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment