Skip to content

Instantly share code, notes, and snippets.

@chicagoworks
Created December 25, 2010 16:00
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 chicagoworks/754928 to your computer and use it in GitHub Desktop.
Save chicagoworks/754928 to your computer and use it in GitHub Desktop.
load and parse querystring, then append to name/values to window.location.query
(function() {
var arr = decodeURIComponent(window.location.search.substr(1)).replace(/\+/g," ").split('&'), p;
window.location.query = {};
for (var i = 0; i < arr.length; i++) {
p = arr[i].split('=');
window.location.query[p[0]] = p[1];
}
})();
@chicagoworks
Copy link
Author

index.html?foo=123&bar=x+y+z

window.location.query[foo] => 123
window.location.query[bar] => 'x y z'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment