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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Go to a specific page if a condition is not met

    I would like to put coding in some of my pages so that depending on the previous page the visitor came from, he is send to a specific page.

    I mean:
    in page B.htm
    if the previous page is not page A.htm got to page A.htm
    else show page B.htm

    ie. The only way to visit page B.htm is when you came from page A.htm

    Anybody who can help me?
    thanks

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    <head>
    <script type = "text/javascript">
    if (document.referrer.indexOf("http://www.yourURL.com") == -1) {
    location.href = "http://www.yourURL.com/pageA.html";
    }
    </script>
    </head>

  • Users who have thanked Philip M for this post:

    gijssr (08-26-2007)

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thanks

    Philip M,
    This was exactly what I was looking for.

  • #4
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    After testing:
    Works fine with firefox
    Microsoft Internet explorer sends you to page A.htm even when you come from page A.htm
    Anybody any ideas

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Try this on page B:
    Code:
    if (document.referrer.indexOf('pageA') == -1) {
    location.replace('http://www.yourURL.com/pageA.html');
    }
    Last edited by rwedge; 08-26-2007 at 11:25 PM.

  • Users who have thanked rwedge for this post:

    gijssr (08-28-2007)

  • #6
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks Rwedge,
    but this coding has the same effect.
    It looks like a bug? in the Internet Explorers Javascript interpreter:
    The refering page (Page A)(to which I don't want to go back if I come from there) generates the destination page (page B) by a piece of javascript coding:
    top.location=..............
    Then after arriving at page B, document.referrer is empty.
    even if I put a complete "url" after top.location= ;
    in short:
    document.referrer does not contain an address using Internet Explorer (coming from a page where top.location was the destination) while using Firefox it contains the correct url.

    Any further ideas are very welcome.
    Last edited by gijssr; 08-27-2007 at 04:10 PM. Reason: clarify


  •  

    Posting Permissions

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