Results 1 to 2 of 2

Thread: Can javascript be modified to include exceptions?

  1. #1
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can javascript be modified to include exceptions?

    Hello,

    I have located several codes for exit popups, but my problem is that they popup when customers navigate to other pages instead of only when they leave the site. My understanding is that the code does not distiguish between going to another page or leaving the site. Is there a way to modify this script with exceptions, such as popup except when "Continue" or "Back" buttons are clicked? Also the page I want to use this script on is www.suitsabounding.com/before_payment.asp

    The ultimate goal is to offer customers that are leave my site a discount if they purchase today.

    The code I am using is

    <head>

    <script language="JavaScript">
    <!--

    function CreateCookie(name, value, expiredays)
    {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + " = " + value + "; expires=" +
    todayDate.toGMTString() + ";";
    }

    function ReadCookie(cookiename)
    {
    var numOfCookies = document.cookie.length;
    var nameOfCookie = cookiename + "=";
    var cookieLen = nameOfCookie.length;
    var x=0;
    while (x <= numOfCookies)
    {
    var y = (x + cookieLen);
    if (document.cookie.substring(x, y) == nameOfCookie)
    return(ExtractCookieValue (y));
    x = document.cookie.indexOf(" ", x) + 1;
    if (x == 0)
    break;
    }
    return null;
    }

    function ExtractCookieValue(val)
    {
    if ((endOfCookie = document.cookie.indexOf(";", val)) == -1)
    {
    endOfCookie = document.cookie.length;
    }
    return unescape(document.cookie.substring(val, endOfCookie));
    }

    function GoodBye()
    {

    if (confirm("\nDON'T GO! We will give you an additional 10% off if you continue with your purchase today. Use coupon code TodayOnly\n"))
    {
    window.open("http://www.suitsabounding.com/before_payment.asp");
    }
    else
    {
    alert("\nGod Bless\n & we hope to see you again soon.\n");
    return false;
    }
    }

    function MainGoodBye()
    {
    var userCookie = ReadCookie("_chups");
    if (userCookie == null)
    {
    // user is here at first time
    //propose to visit site
    GoodBye();
    //create coockie key (30 days)
    CreateCookie("_chups", 1, 30);
    }
    }
    //-->
    </script></head>


    <body onunload="MainGoodBye()">

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    First, you have your GoodBye function backward; returning false keeps the user on your page, so you're bidding farewell when they're staying.

    The only way I can think of to include such an exception is to find every link in the page (document.getElementsByTagName('a');) and, if it links to a local/inside page, set its onclick to somehow change the page's state to reflect the link's href then return true. If the page's state is the default, the user either clicked a remote/outside link or tried to close the window or tab.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

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
  •