Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created February 20, 2015 07:10
Show Gist options
  • Save yorkie/e0e598cbb2154d7b5979 to your computer and use it in GitHub Desktop.
Save yorkie/e0e598cbb2154d7b5979 to your computer and use it in GitHub Desktop.
function parseQuerystring (key) {
var href = location.href;
var start = href.indexOf('?');
var obj = href.slice(start+1).split('&');
var ret = {};
obj.forEach(function (item) {
var vals = item.split('=');
var key = vals[0];
var val = decodeURI(vals[1]).replace(/\+/g, ' ');
ret[key] = val;
});
if (!key)
return ret;
else
return ret[key];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment