|
Q93 How can I redirect a visitor to separate pages, keeping the domain name they came in with based on the referrer?
irt.org | Knowledge Base | JavaScript | Misc | Q93 [ previous next ]
Q93 How can I redirect a visitor to separate pages, keeping the domain name they came in with based on the referrer?
Using JavaScript I can think of two possible solutions, one that will not work on Internet Explorer and the other
that will work on all JavaScript capable browsers:
<script language="JavaScript"><!--
var who = document.referrer;
if (who.indexOf('www.domain1.com') != -1)
window.location.href = 'http://www.domain1.com/domain1/';
if (who.indexOf('www.domain2.com') != -1)
window.location.href = 'http://www.domain2.com/domain2/';
else
alert('Where DID you come from?');
//--></script>
|
This method requires that the originating link passes a value in the search parameter, e.g.:
<a href="http://www.domain.com/index.html?1">coming from 1</a>
|
or
<a href="http://www.domain.com/index.html?2">coming from 2</a>
|
and then on the index.html page:
<script language="JavaScript"><!--
var who = window.location.search.substring(1);
if (who == '1')
window.location.href = 'http://www.domain1.com/domain1/';
if (who == '2')
window.location.href = 'http://www.domain2.com/domain2/';
else
alert('Where DID you come from?');
//--></script>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.