Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read a parameter from another page? 1

Status
Not open for further replies.

royboy75

Programmer
Feb 13, 2007
114
GB
Hello,

I am referring to another html page using the standard link tag: <a href="intro.html"...
Suppose I am transferring a parameter to this page, like this: <a href="intro.html?myVal=hello"...
Is it possible to read it from the intro.html file using client side technologies, such as plain html or javascript?



 
Hi

You find the parameters in the [tt]location[/tt] object's [tt]search[/tt] property. But you will need to split it.
Code:
[b]var[/b] par=[b]new[/b] Array();
[b]var[/b] parStr=location.search.replace(/^\?/,[i]''[/i]).split(/[&;]/);
[b]for[/b] (i=0;i<parStr.length;i++) {
  [b]var[/b] part=parStr[i].split(/=/,2);
  par[part[0]]=part[1];
}
And after the above you will have the parameters in the par [tt]Array[/tt].

Feherke.
 
Hi

Oops. And if you need special characters too, then change the last line to decode eventual URLEncoded entities :
Code:
  [gray]...[/gray]
  par[unescape(part[0].replace(/\+/g,[i]' '[/i]))]=unescape(part[1].replace(/\+/g,[i]' '[/i]));
}

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top