DelphiFAQ Home Search:
General :: Web publishing :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Dynamic content based on referrer (using client side javascript)


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';


Generated 0:01:45 on Jan 24, 2020