DelphiFAQ Home Search:

Dynamic content based on referrer (using client side javascript)

 

comments4 comments. Current rating: 3 stars (1 votes). Leave comments and/ or rate it.

Question:

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

Answer:

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('url1.com') > -1)
    location.href = 'index1.html';
else if (document.referrer.indexOf('url2.com') > -1)
    location.href = 'index2.html';
else
   location.href = 'index0.html';
//-->

</script>

Content-type: text/html

Comments:

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('url.com')> -1)
location.href='error_menu.htm';
else
location.href='default_menu.htm';

close script here

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

This worked better for me
<script language='JavaScript'>


matua105@gmail.com
2012-11-12, 05:30:47
anonymous from United States  
2019-05-14, 05:16:11
anonymous from Colombia  
rating
Hey,

I can't believe that ThePornDude site is also selling prescription meds without any prescription! I've seen this: [url= https://theporndude...os/]viagra prank[/url] on that guy with boner problem site. As I mentioned before, its name is 'ThePornDude'. Quite lame site though. I am wondering, why police are not after this viagra lover?

Look for the news!Keep in touch!

 

 

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: