SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    USA
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check referer to page

    Hello,
    I have a warning that I want the surfer to see before they get to my home page as my index.htm file. I want to ensure that the surfer does nor link to my home page without first seeing the warning, but the rest of my pages also link to my home page. How do I code it so that if the referer to my home page is not my index.htm or any other of my pages in the site, to automatically redirect to the index.htm(warning page)?

    Thank You

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi arkosh,

    Put this simple code in your pages that you want to check:
    Code:
    <script type="text/javascript">
    if (document.referrer && (document.referrer.indexOf(document.domain) == -1))
    {
    	window.location = 'index.htm';
    }
    </script>
    It checks to see if the referrer came form any page on your site and if they didn't they will be redirected to your warning page.

    -xDev

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    USA
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot xdev! Should this be in a function that I call with the onload, or can I put it in my script tags(as shown) and it will automatically run.

  4. #4
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkosh
    Thanks alot xdev! Should this be in a function that I call with the onload, or can I put it in my script tags(as shown) and it will automatically run.
    Just put the above code, as is, between the head tags.. that will do it. The if conditional will take care of everything.

    Cheers,
    -xDev

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    USA
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again xDev!


Bookmarks

Posting Permissions

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