Skip to content

Instantly share code, notes, and snippets.

@fuzzyfox
Created October 16, 2013 09:22
Show Gist options
  • Save fuzzyfox/7005025 to your computer and use it in GitHub Desktop.
Save fuzzyfox/7005025 to your computer and use it in GitHub Desktop.
JavaScript: querystring to json object
// utility function to parse/use query strings
window.query = document.query = (function(window, document, undefined){
var pairs = window.location.search.slice(1).split('&'),
result = {};
pairs.forEach(function(pair){
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1] || '');
});
return JSON.parse(JSON.stringify(result));
})(this, this.document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment