Skip to content

Instantly share code, notes, and snippets.

@kodaka
Last active December 20, 2015 22:38
Show Gist options
  • Save kodaka/6206283 to your computer and use it in GitHub Desktop.
Save kodaka/6206283 to your computer and use it in GitHub Desktop.
Parse QUERY_STRING.
// "?a=1&a=2&b=x&c=%2A&d=&=y&=&==&%2A=3&" -> Object {a: "2", b: "x", c: "*", d: "", %2A: "3"}
var q = (function(){
var q = {};
window.location.search
.substring(1)
.split('&')
.filter(function(a){
return a.indexOf('=') > 0;
})
.forEach(function(a){
var p = a.split('=');
q[p[0].trim()] = decodeURIComponent(p[1]).trim();
})
;
return q;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment