homepage Welcome to WebmasterWorld Guest from 54.227.25.58
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript to detect certain referrers
Check Part of Domain name against a list
Rhys




msg:3761910
 9:55 am on Oct 9, 2008 (gmt 0)

I need this script to cycle thru an array and check if some word in the referrer's name is on a list - something like this?

<script language="JavaScript">
<!--
var myArray = [];
x[0]= 'domain1';
x[1]= 'domain2';
x[2]= 'domain3';
x[3]= 'domain4';
x[4]= 'domain5';
for(i=0;
i<5;
i++) {
if (document.referrer.indexOf(!myArray.indexOf') > -1);
}
document.write('Some Text goes here');
//-->
</script>

 

Receptional Andy




msg:3761934
 10:39 am on Oct 9, 2008 (gmt 0)

You have the right idea - you need to loop through the array and check each entry against the referrer. Something like

var myArray = [];
myArray[0]= 'domain1';
myArray[1]= 'domain2';

var currentReferrer=document.referer;

var i;
for (i=0;i<myArray.length;i++)

// match() may be more effective than looking for an exact value
if (myArray[i] === currentReferrer) {

// the referrer matched one in the list
alert("matched referrer");

}


daveVk




msg:3761943
 10:46 am on Oct 9, 2008 (gmt 0)

Try these changes, you may also need to wait for page onload.

<script language="JavaScript">
<!--
var myArray = [];
myArray[0]= 'domain1';
myArray[1]= 'domain2';
myArray[2]= 'domain3';
myArray[3]= 'domain4';
myArray[4]= 'domain5';
for(
var i=0;
i<5;
i++) {
if (document.referrer.indexOf(
myArray[i]) > -1)
{
document.write('Some Text goes here');
}}
//-->
</script>

Rhys




msg:3761947
 10:53 am on Oct 9, 2008 (gmt 0)

Him Andy - thanks for the reply.

It doesn't fit what I need -
I need check "some word in the referrer's name is on a list"; not the whole referrer.

Rhys




msg:3761951
 10:58 am on Oct 9, 2008 (gmt 0)

Hi DaveVK -

You're the Man - it worked instantly with your edits - many thanks.

Rhys

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved