Easily handle parameters in the search part of a URLTag(s): Language


You can extract the parameters into an array
<HTML><HEAD></HEAD><BODY>
<SCRIPT>
TheParameters  = document.location.search.substring(1,255)
alert(TheParameters)
TheParametersArray = TheParameters.split("&")

k = TheParametersArray.length
for (i= 0 ; i < k; i++) {
 alert(unescape(TheParametersArray[i]))
  }
</SCRIPT></BODY></HTML>
or use a regular expression
<HTML><HEAD></HEAD><BODY>
<SCRIPT>

function getParameter(p) {
// returns NULL if the parameter p is not found
 var re = new RegExp('&'+p+'=([^&]*)','i');
 // for testing, 
 //   replace with window.location.search in real life!
 var c = '?apple=steve&pc=bill&a='; 
 return (c=c.replace(/^\?/,'&').match(re)) ?c=c[1] :c='NULL';
};

// Testing:
alert(getParameter('pc'));
alert(getParameter('qqq'));
alert(getParameter('aPPLE'));
alert(getParameter('A'));
</SCRIPT></BODY></HTML>

blog comments powered by Disqus