...

View Full Version : Jacascript Redirect



Acid Rainbow
04-18-2007, 07: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.


<SCRIPT TYPE="TEXT/JAVASCRIPT">
if (document.referrer = "http://www.freewebs.com/stormhorizon/test1.htm")
{
location.href = "http://www.freewebs.com/stormhorizon/test3.htm";
}
</SCRIPT>

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.

riptide
04-18-2007, 07:45 PM
what is referrer

Acid Rainbow
04-18-2007, 07: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.

JUD
04-18-2007, 08: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, 09:38 PM
Ah, perfect.

Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum