Skip to content

Instantly share code, notes, and snippets.

@nikyodo85
Created October 16, 2018 17:30
Show Gist options
  • Save nikyodo85/880b488d79498dfd0dd47dc6007053a0 to your computer and use it in GitHub Desktop.
Save nikyodo85/880b488d79498dfd0dd47dc6007053a0 to your computer and use it in GitHub Desktop.
Function to extract query string from address bar and return them as Javascript array. Usage: var qs = getQueryString(); var value = qs["key"];
function getQueryString() {
var qsDict = {};
var qs = location.search.substr(1).split("&");
function decode(s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
for (var i = 0; i < qs.length; i += 1) {
var qKV = qs[i].split('=');
if (qKV.length > 1) {
qsDict[decode(qKV[0])] = decode(qKV[1]);
}
}
return qsDict;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment