Forum Moderators: open

Message Too Old, No Replies

Link Referral Location

Showing a message if the user came to the page via a page on same domain

         

SomePerson6

12:43 am on Oct 23, 2008 (gmt 0)

10+ Year Member



Hello,

I've heard that this is a fairly simple thing to accomplish, but am stuck as to how to proceed. Basically, I want a JavaScript function to run if the user accessed the page via a link on any page from the same domain.

For example, if my site is example.com, and a user clicks on a link leading to example.com from example.com/links.html - there would be a piece of JavaScript on example.com that would distinguish a user who visited from any page on the example.com domain (such as links.html) between someone who visited it from, say, Google, that would look something like this (obviously substituting in words for the missing part I don't know how to accomplish):

if (link referral location = mydomain.com)
{
document.write('You arrived at this page from a link on this same site!');
}

Is something along the lines of this possible, or must this be done with cookies instead?

Help would be greatly appreciated - thanks in advance! :)

[edited by: SomePerson6 at 12:45 am (utc) on Oct. 23, 2008]

daveVk

2:46 am on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if ( document.referrer.indexOf( 'mydomain.com' ) > -1 )
{
document.write('You arrived at this page from a link on this same site!');
}