Created
January 21, 2019 15:29
-
-
Save lancevo/86e1bea13eee57da89ad40effd4fafc5 to your computer and use it in GitHub Desktop.
extracts and parses url query string
This file contains hidden or 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(window){ | |
'use strict'; | |
function getQuery(query){ | |
var args = decodeURIComponent(location.search).substring(1).split('&'); | |
var argsParsed = {}; | |
var i, arg, kvp, key, value; | |
for (i=0; i < args.length; i++) { | |
arg = args[i]; | |
if (-1 === arg.indexOf('=')) { | |
argsParsed[decodeURIComponent(arg).trim()] = true; | |
} | |
else { | |
kvp = arg.split('='); | |
key = decodeURIComponent(kvp[0]).trim(); | |
value = decodeURIComponent(kvp[1]).trim(); | |
argsParsed[key] = value; | |
} | |
} | |
return argsParsed[query]; | |
} | |
window.getQuery = window.getQuery || getQuery; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment