View Full Version : Jacascript Redirect

Acid Rainbow
04-18-2007, 08:32 PM
I know the general redirect code, but what I want is for it to only redirect if the user is coming from a certain page. I got this code, however it doesn't redirect at all with it.

if (document.referrer = "http://www.freewebs.com/stormhorizon/test1.htm")
location.href = "http://www.freewebs.com/stormhorizon/test3.htm";

I've tried various alterations, including adding an "else" command, but still to no avail. I was wondering if there was anything wrong, or if it's simply the site I'm using.

The code is here (http://www.freewebs.com/stormhorizon/test2.htm), if you wanted to look. I want it redirect only from this (http://www.freewebs.com/stormhorizon/test1.htm) page.

Any help would be much appreciated.

04-18-2007, 08:45 PM
what is referrer

Acid Rainbow
04-18-2007, 08:56 PM
"referrer" is the referring page.

For example, when you click into this thread from the "JavaScript programming" topic, your referring page would be "http://www.codingforums.com/forumdisplay.php?f=2" aka, the JavaScript programming topic.

04-18-2007, 09:49 PM
The problem is in your if statement.

In javascript "=" is used to assign a value to something. To test if something is equal to something else you should use "==".

So your if statement should look like this:

if (document.referrer == "http://www.freewebs.com/stormhorizon/test1.htm")

Acid Rainbow
04-18-2007, 10:38 PM
Ah, perfect.

Thank you.