Friday 7 March 2008

Stripping the URL parms using Javascript (quick tip)

If you need to look at the parm strings in the current URL here is a way to do it that loads
the parms as JS vars, so

Once the code below has run will result in 2 JS vars called q1 and q2 which you can then act on.

myArray = document.location.href.split('?')[1].split('&');
for(x=1; x<myArray.length; x++)
var tmp = myArray[x].split('=');
eval(unescape(tmp[0]) + '="' + unescape(tmp[1]) + '"');

The count x starts a 1 to avoid you having an undefined JS var called openpage


No comments:

Disqus for Domi-No-Yes-Maybe