Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created June 15, 2011 09:36
Show Gist options
  • Select an option

  • Save barneycarroll/1026798 to your computer and use it in GitHub Desktop.

Select an option

Save barneycarroll/1026798 to your computer and use it in GitHub Desktop.
Return an object model of a URI query (search or hash)
/* Return an object model of a URI query (search or hash) */
function uriQueryObj(str){
if(!str) return false;
var str = decodeURIComponent(str),
str = /(^#)|(^$)/.test(str) ? str.substr(1) : str,
arr = str.substr(1).split('&'),
hash = {};
while(arr.length && arr[0]){
var bits = arr.pop().split('=')
hash[bits[0]] = bits[1] || bits[0];
}
return hash;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment