Created
February 7, 2012 22:53
-
-
Save listenrightmeow/1762686 to your computer and use it in GitHub Desktop.
queryParams
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
queryParams: function() { | |
var query = {}, | |
search = window.location.search, | |
fields = ['postalcode', 'range', 'franchise']; | |
fields.map(function(param){ | |
var p = escape(unescape(param)), | |
regex = new RegExp("[?&]" + p + "(?:=([^&]*))?","i"), | |
match = regex.exec(search); | |
if(match == null) return; | |
query[param] = match[1]; | |
}); | |
console.log(query); | |
} | |
// New version | |
queryParams: !function(search, match, tmp , regex) { | |
tmp = {}; regex = /([^?&;=]+)=?([^?&;]*)/g; | |
while(match = regex.exec(search.substr(1))) tmp[match[1]] = match[2]; | |
params['values'] = tmp; | |
}(window.location.search) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment