I always stick this as one line. Now params has the vars:
params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v}) multi-lined:
var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); as a function
function getSearchParams(k){ var p={}; location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v}) return k?p[k]:p; } which you could use as:
getSearchParams() //returns {key1:val1, key2:val2} or
getSearchParams("key1") //returns val1