Last active
August 31, 2018 21:14
-
-
Save wxactly/8417964a4bfb98747d1b68185717e66e to your computer and use it in GitHub Desktop.
Get query parameters as an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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