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
    Oct 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    prompt referrer only for outside domain

    I want to modify the cofirm javascript prompt below to use as a disclaimer on my main page. but I'd like to modify it so that a person will see it when they come to the main page from another site outside my domain, www.whatever.com. So that if they are on another page within my domain and click to go to index.html, they will not see the prompt.

    Thanks in advance for the help

    <SCRIPT LANGUAGE="JavaScript">

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    var agree=confirm("I'd like to show you how to get this exact JavaScript message script. OK?");
    if (agree)
    document.write("");
    else
    history.go(-1);
    // End -->
    </SCRIPT>

  • #2
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <SCRIPT LANGUAGE="JavaScript">

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    <!-- Begin
    // http://coffeedemon.com/) = 24 chars
    // http://www.coffeedemon.com/ = 28 chars

    /********************************************
    document.referrer gets the referrering address

    substr(0,23)

    this function will take a string like "http://coffeedemon.com/dir/dir/dir/dir/index.cd" and extract the first 23 charactors starting at 0 making it
    "http://coffeedemon.com/"

    document.refferrer.substr(0,23) replace the last charactor by the length of your site including "http://" and the ending "/" then subtract 1. do the same for
    the second substr() but cound the length including "www." (add 4 to previous count) and subtract one.
    *********************************************/

    var agree=confirm("I'd like to show you how to get this exact JavaScript message script. OK?");

    if(document.referrer.substr(0,23) == "http://coffeedemon.com/" !| document.referrer.substr(0,27) != "http://www.coffeedemon.com/")
    {
    if (agree)
    {
    document.write("");
    }
    else
    {
    history.go(-1);
    }
    }
    // End -->
    </SCRIPT>

    Hope this helps
    Last edited by Phip; 10-26-2003 at 01:22 AM.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you have your own Domain you can try this.
    It's best used if you use IP#'s eg: 216.32.421.12

    If you can not use Server Side to store acceptance of the
    Disclaimer. I would use cookies to store the info. Some sites do
    not send a referrer, javascript could fail or stall, many things can
    happen to kill or disable this script.

    <script type="text/javascript">
    <!--//

    // Check if Referrer is within Domain. If so, stay on page
    function goodUrl() {
    a = location.href;
    if (document.referrer.indexOf("http://www.whatever.com") > -1) {
    a = a;
    alert('Location.HREF='+a);
    }
    }
    // Check if Referrer is within Domain. If no, choose OK or CANCEL
    function badUrl() {
    alert('Document.Referrer='+document.referrer);
    if (document.referrer.indexOf("http://www.whatever.com") == -1){
    agree = (confirm("You have come here from outside of the Domain.\nClick OK to proceed to our Main Entrance Page.\nClick CANCEL to return to wence you came from.") ? "yes" : "no")
    }
    // Check if Bad Referrer wishes to stay, If yes, GoTo Main Page
    if (document.images && agree == "yes") {
    location.replace("http://whatever.com/index.html")
    }
    // Check if Bad Referrer wishes to stay, If no, GoBack one page
    if (document.images && agree == "no") {
    history.go(-1);
    }
    }

    function chkUrl() {
    goodUrl();
    badUrl();
    }

    window.onLoad=chkUrl();
    //-->
    </script>

    Remove Alerts once you understand
    how the script is running.

    .....Willy

  • #4
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys - both unique ways of doing the same thing

    If anyone else uses this, the script that Phip created has a typo in "if line" should be || not !| - but I have done that a thousand times myself

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I like Phip's better for its straightforwardness.

    But in defense of my lengthy example. It will redirect a user
    to your index page if they enter your site thru a backdoor.

    ......Willy


  •  

    Posting Permissions

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