Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Jacascript Redirect

    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.

    Code:
    <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, if you wanted to look. I want it redirect only from this page.

    Any help would be much appreciated.

  • #2
    Regular Coder riptide's Avatar
    Join Date
    Jan 2007
    Posts
    143
    Thanks
    1
    Thanked 0 Times in 0 Posts
    what is referrer

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "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.

  • #4
    JUD
    JUD is offline
    New Coder
    Join Date
    Jul 2005
    Location
    I'm right here
    Posts
    92
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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:

    Code:
    if (document.referrer == "http://www.freewebs.com/stormhorizon/test1.htm")
    Last edited by JUD; 04-18-2007 at 08:51 PM.

  • #5
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, perfect.

    Thank you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •