DelphiFAQ Home Search:

Dynamic content based on referrer (using client side javascript)


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.


How do I detect the referrer in order to display the appropriate content?


Such things should really happen on the server side. The reason is that some browsers may not support javascript (Lynx) or the user may have disabled javascript for security reasons.

However, if you have a static HTML page and it is beyond your control to change this into a server side parsed document (typically by renaming it to .SHTML) and you cannot change the web server's configuration to do parsing on HTML pages.. and you cannot use php or jsp.. only in this situation it is justified to use javascript for content selection.

The example does a redirect depending on from which page your request came. The referrer is a property of the document and indexOf() is used to check for a relevant substring.

<script language="JavaScript">
if (document.referrer.indexOf('') > -1)
    location.href = 'index1.html';
else if (document.referrer.indexOf('') > -1)
    location.href = 'index2.html';
   location.href = 'index0.html';


Content-type: text/html


2007-12-01, 19:27:48   (updated: 2007-12-01, 19:34:59)
anonymous from United States  

This worked better for me

put script language equals javascript here

if !(document.referrer.indexOf('')> -1)

close script here

sorry i attempted to put the code in with the javascript above but the code was not reflected above
2007-12-01, 19:30:53
anonymous from United States  

This worked better for me
<script language='JavaScript'>
2012-11-12, 05:30:47
anonymous from United States  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: