Introduction
One of the things that can get overlooked in web development is the fact that you can pass parameters to HTML pages without having to bounce a redirect statement off the server. This can be pretty useful if the HTML page is a generic that loads various xml files based on that parameter (like a product details page with a productID being passed).
Here's the code:
function retVal(sName)
{
var sURL = new String(window.location);
var iQMark= sURL.lastIndexOf('?');
var iLensName=sName.length;
var iStart = sURL.indexOf('?' + sName +'=') if (iStart==-1)
{ iStart = sURL.indexOf('&' + sName +'=') if (iStart==-1)
{ return 0; }
}
iStart = iStart + + iLensName + 2;
var iTemp= sURL.indexOf('&',iStart); if (iTemp ==-1)
{ iTemp=sURL.length;
}
return sURL.slice(iStart,iTemp ) ;
sURL=null;}
alert( retVal('mynewname'));
Usage:
Save the code into a normal HTML page and call it like this:
mypage.htm?mynewname=testvalue
and "testvalue" should be returned in the alert box. The "mynewname" is just
a literal and can be replaced with any querystring name that has a
value related to it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here