Friday, November 14, 2008

JavaScript: Get URL Parameters

var _GET={};
for(var m, v=location.href.split(/[?&]/), k=v.length-1;k>0;k--)
_GET[(m=v[k].split(/[=#]/))[0].toLowerCase()] = m.length>1?decodeURI(m[1]):"";

example:

mypage.aspx?MyParameter=2

var param=_GET.myparameter; (always use lowercase)

No comments: