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!

need help with document.referrer.indexof

Status
Not open for further replies.

acrinsd

Programmer
May 19, 2010
1
US
I am attempting to build some logic based on the referring information containing a particula domain name. This is easy enough when I am only looking for one domain, but I have been asked to include multiple domains that may be a match. Once I attempt to use more than one domain, the whole things falls apart. In these examples, if I use "abc" to test, it works correctly and placeHolder is set to One. If I change it to "def" or any other string, I get "None" as the value.

Any guidance would be greatly appreciated.

Sample of the code I am using:
Code:
<script language="javascript">
var myRef=new Array("abc","def","ghi","jkl","mno","pqr","stu","vwx","yzz");
</script>
<SCRIPT LANGUAGE="JavaScript">
if(document.referer.indexOf(myRef) != -1){
    placeHolder = "One";
} else {
    placeHolder = "None";
}
</SCRIPT>
I have also tried using something like this in the indexof, but it doesn't work either.

Code:
<SCRIPT LANGUAGE="JavaScript">
if(document.referrer.indexOf("abc"||"def"||"ghi"||"jkl"||"mno"||"pqr"||"stu"||"vwx"||"yzz") != -1){
    placeHolder = "One";
} else {
    placeHolder = "None";
}
</SCRIPT>
 
1. Your first code is sing referer with a single R, while the actual property is spelled with 2 refe[red]rr[/red]er as you types in your post title.

2. I don't believe the indexOf function works off of arrays as the parameter. Only a single string.


I guess you could always loop through the array and test each individual value, if you get a hit then you can break the loop then.

Code:
for(var x in myRef){
if(document.referrer.indexOf(myRef[x]) != -1){
    var placeHolder = "One";
break;
} else {
    var placeHolder = "None";
}
}



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top