1 function getQuery () { 2 var args = {}; 3 var query = window.location.search.substring(1); 4 var pairs = query.split("&"); 5 for(var i = 0; i < pairs.length; i++) { 6 var pos = pairs[i].indexOf('='); 7 if (pos == -1) continue; 8 var argname = pairs[i].substring(0, pos); 9 var value = pairs[i].substring(pos+1); 10 value = decodeURIComponent(value); 11 args[argname] = value; 12 } 13 return args; 14 } 15 or 16 function getQuery () { 17 var ret = {}, 18 seg = location.search.replace(/^?/,'').split('&'), 19 len = seg.length, i = 0, s; 20 for (;i<len;i++) { 21 if (!seg[i]) { continue; } 22 s = seg[i].split('='); 23 ret[s[0]] = decodeURIComponent(s[1]); 24 } 25 return ret; 26 }