Skip to content

Instantly share code, notes, and snippets.

@NV
Created October 19, 2009 17:11
Show Gist options
  • Save NV/213522 to your computer and use it in GitHub Desktop.
Save NV/213522 to your computer and use it in GitHub Desktop.
Handy URL params access
/*
* Handy URL params access
* @example
* location.href = 'http://www.google.com/search?q=foo+bar&client=firefox'
* location.params == {q: 'foo+bar', client: 'firefox'}
*/
// JS 1.6
location.params = {};
location.search.substr(1).split('&').forEach(function(el){
var key = el.split('=')[0];
var value = el.split('=')[1];
location.params[key] = value;
});
// JS 1.7 (Can non-python programmers read it?)
location.params = {};
[location.params[y[0]]=y[1] for each (y in [x.split('=') for each (x in location.search.substr(1).split('&'))])];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment