Created
October 16, 2018 17:30
-
-
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"];
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 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