Skip to content

Instantly share code, notes, and snippets.

@06b
Last active August 29, 2015 13:56
Show Gist options
  • Save 06b/8871556 to your computer and use it in GitHub Desktop.
Save 06b/8871556 to your computer and use it in GitHub Desktop.
Get Query String Values
// http://stackoverflow.com/a/3855394
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
//With an URL like ?topic=123&name=query+string, the following will return:
//qs["topic"]; // 123
//qs["name"]; // query string
//qs["nothere"]; // undefined (object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment