View Single Post
  #2 (permalink)  
Old July 8th, 2004, 04:45 PM
Snib Snib is offline
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The easiest approach would be to use a server language, perhaps PHP, ASP or CGI.

If you have access to any of those, go with that. Otherwise, you'll need a function that parses the querystring and gets the string between the '=' sign and the '&' sign (or the end of the string).

I found this Googling:

function querystring(key)
{
 var value = null;
 for (var i=0;i<querystring.keys.length;i++)
 {
  if (querystring.keys[i]==key)
  {
   value = querystring.values[i];
   break;
  }
 }
 return value;
}

querystring.keys = new Array();
querystring.values = new Array();

function querystring_parse()
{
 var query = window.location.search.substring(1);
 var pairs = query.split("&");

 for (var i=0;i<pairs.length;i++)
 {
  var pos = pairs[i].indexOf('=');
  if (pos >= 0)
  {
   var argname = pairs[i].substring(0,pos);
   var value = pairs[i].substring(pos+1);
   querystring.keys[querystring.keys.length] = argname;
   querystring.values[querystring.values.length] = value;
  }
 }
}
querystring_parse();

Supposedly you can do this:

var x = querystring("x");

....to get the value of any querystring variable.

So if you were at http://www.yoursite.com/folder/something.html?x=hello, using the above code would set x to "hello".

I haven't tried the script, so let me know if it works.

HTH,

Snib

<><
Reply With Quote