Skip to content

Instantly share code, notes, and snippets.

@wxactly
Last active August 31, 2018 21:14
Show Gist options
  • Save wxactly/8417964a4bfb98747d1b68185717e66e to your computer and use it in GitHub Desktop.
Save wxactly/8417964a4bfb98747d1b68185717e66e to your computer and use it in GitHub Desktop.
Get query parameters as an object
function getQueryParameters(queryString) {
queryString = (queryString || document.location.search).replace(/(^\?)/, '');
var queryParams = {};
if (queryString) {
var keyVals = queryString.split('&');
for (var i = 0; i < keyVals.length; i++) {
var keyVal = keyVals[i].split('=');
queryParams[keyVal[0]] = decodeURIComponent(keyVal[1].replace(/\+/g, '%20'));
}
}
return queryParams;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment