Skip to content

Instantly share code, notes, and snippets.

@lancevo
Created January 21, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancevo/86e1bea13eee57da89ad40effd4fafc5 to your computer and use it in GitHub Desktop.
Save lancevo/86e1bea13eee57da89ad40effd4fafc5 to your computer and use it in GitHub Desktop.
extracts and parses url query string
(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