Skip to content

Instantly share code, notes, and snippets.

@listenrightmeow
Created February 7, 2012 22:53
Show Gist options
  • Save listenrightmeow/1762686 to your computer and use it in GitHub Desktop.
Save listenrightmeow/1762686 to your computer and use it in GitHub Desktop.
queryParams
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