SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Site Exit Pop-up window

    Hello I am trying to find code that will do the following:

    Have a pop-up window invitation only come up after the visitor has left the Web site domain. Example: A visitor goes to XX.com, visits the home page, weather page, sports page - and then goes to ZZ.com. The pop-up window would come up after the sports page (right before going to ZZ.com). I would also like the pop-up window to come up only once per person (example the pop-up would not appear the next day), and have it come up randomly (not to every visitor). Has anyone done a pop-up window like this in the past?


    I have heard of a company that has done something similar to this in the past but no idea of what the code looked like. What they did was to place the code on every main point of entry to their site. Once a customer goes to that point of entry the code would run and open a daughter window (Minimized). Then once they leave the domain, from any page, the pop-up would launch.

    Does anyone know what the code would be to do that? I do not know if the following would help, but the code below develops a pop-up window randomly, and it is only offered once per person with the cookie expiring after one year. If anyone could help me figure out how to achieve the pop-up window to come up after leaving a Web domain, please let me know. Thank you.


    <head>

    <SCRIPT LANGUAGE="JavaScript">

    <!--// Intercept - executed on page load
    //***************************************************

    var pctOfferedSurvey = .5;
    var popupLocation = "http://www.espn.com";
    var cookieSurveyDisplayed = "example";

    var expDate = new Date ();
    var milOneYear = (365 * 24 * 60 * 60 * 1000);
    var storedValue;

    expDate.setTime (expDate.getTime() + milOneYear);
    storedValue = GetCookie(cookieSurveyDisplayed);
    cn = Math.random();
    //alert('random ' + cn);
    //alert('cookie ' + storedValue);
    //alert(cn <= pctOfferedSurvey) && (storedValue == null);

    function errortrap(msg,url,line)
    {
    GenRandomIntercept();
    }

    onerror = errortrap;

    function GenRandomIntercept()
    {
    if ((cn <= pctOfferedSurvey) && (storedValue == null))
    {
    SetCookie(cookieSurveyDisplayed, 'alreadyOffered', expDate, '/');
    window.open(popupLocation,'intercept','width=385,height=390,screenX=20,screenY=200,top=20,left=200');
    }
    }

    function GetCookie (name)
    {
    var mycookie = document.cookie;
    var start = mycookie.indexOf(name, 0);
    if(start >= 0)
    {
    var end = mycookie.indexOf(';', start);
    if(end < 0)
    {
    end = mycookie.length;
    }
    return mycookie.substring(start, end);
    }
    else
    {
    return null;
    }
    }

    function SetCookie (name,value,expires,path,domain,secure)
    {
    document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
    }

    //************************************************************************************
    //-->

    </SCRIPT>


    </head>

    <body onload="GenRandomIntercept();">

    </body>

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <body onUnload="GenRandomIntercept();">
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Creole. I do realize that the onUnload will do that for the page the code is on - but I only want the pop-up to come up after they leave the entire Web site domain (not just the page were the code is). Is there an easy way to do that? thanks

  4. #4
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd need to look for a script with some sort of timer in it then. You run the script onunload and it starts counting. X seconds later, the popup window shows up.

    I would ask you, for the good of all mankind though NOT to use this one.

    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes


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
  •