Created
October 19, 2009 17:11
-
-
Save NV/213522 to your computer and use it in GitHub Desktop.
Handy URL params access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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