Re: Using document.referrer before page loads?

by "Jan Morell" <jan_man(at)bellsouth.net>

 Date:  Sat, 24 Feb 2001 10:05:54 -0500
 To:  "Complex" <complex_hwg(at)yahoo.com>,
"Languages HWG" <hwg-languages(at)hwg.org>
 References:  yahoo
  todo: View Thread, Original
Hi Michael,

I just happened to see a script for redirecting the browser to a web page
depending on the document referrer.  It came from CNET's Stupid Web Tricks
page.  I don't know if it is any better than the one that you have or not,
but worth a try. The complete article "Where has that Browser Been?" can be
found at:
http://www.cnet.com/webbuilding/0-7690-8-4671512-1.html?tag=st.bl.7690.dir1.
7690-8-4671512-1

<SCRIPT language="JavaScript">
<!--

function cameFrom(where) {
   if (!document.referrer && !where) return true;
   else return (document.referrer.indexOf(where)>=0)
   }

if (cameFrom("domain1.com")) {
   location.replace("newpage1.html");
   }
else if (cameFrom("domain2.com")) {
   location.replace("newpage2.html");
   }

//-->
</SCRIPT>

Jan

----- Original Message -----
From: "Complex" <complex_hwg(at)yahoo.com>
To: "Languages HWG" <hwg-languages(at)hwg.org>
Sent: Friday, February 23, 2001 3:35 PM
Subject: JS: Using document.referrer before page loads?


I could swear I used to check the identity of document.referrer in the
head, before the page finished loading. However, when I just tried it,
I kept getting a JavaScript error.

I think the error came from trying to get document.referrer before the
page finished loading, but I dont' really know. However, everything
worked when I started using an onLoad handler to check
document.referrer after the page finished loading.

I'd prefer to do this check BEFORE the whole page loads. Can anyone
give me a clue?

This small script is in the head of my corporate site's downloads page:
http://www.scanalytics.com/product/download/index.html.
If you can't type that in directly, and get sent to the "Entry" page,
please just enter "Test(at)test.com" or somesuch as your email address to
get back to the interesting page.


(in head)
<script language="JavaScript" type="text/javascript">
<!--
function HoosierDaddy()
{
var From = document.referrer;
var Good1 = "http://www.longURL.com/index.html";

if (From != Good1)
window.location = Good1;
}
//-->
</script>


Oh, yeah-- the other way to see this is to turn JavaScript off. :-) I'm
not terribly interested in pursuing that huge loophole....

complex

=====
Michael Greisman
Webmaster
Scanalytics, Inc.

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices!
http://auctions.yahoo.com/

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA