SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2000
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello everyone,

    I am looking to collect feedback from my visitors on a certain section of my site. I am looking for a popup that loads upon the exit of a specific page (body onUnload) and once the popup is loaded, I do not want it to load again if that same visit returns. So it will put a cookie into their computer with a certain expiration date. In other words, I want a popup that pops up only once per visitor and that pops up ONLY when the user exits a page.


    HERE IS THE SCRIPT FOR THE ONCE PER VISITOR POPUP:

    <SCRIPT language="JavaScript">
    var oldCookie = document.cookie;
    var number = 0;
    if (oldCookie.indexOf("counter=") < 0){
    number = 1;
    }else{
    number = oldCookie.charAt(oldCookie.indexOf("counter=")+ 8);
    number = parseInt(number) + 1;
    }

    if (number <= 1){
    var exp = new Date();
    var nowPlusOneDay = exp.getTime() + (12 * 60 * 60 * 1000);
    exp.setTime(nowPlusOneDay);
    window.open('page.htm,'pagename','location=0,menubar=0,toolbar=0,person albar=0,status=0,scrollbars=0,width=250,height=250');
    document.cookie="counter=" + number + "; expires=" + exp.toGMTString();
    }

    </SCRIPT>



    The problem with the script above is that it executes as soon as the page is loaded. I want this funtion to be executed upon the exit of a page.


    I MODIFIED THE SCRIPT ABOVE TO MEET MY NEED AND I DON'T THINK IT IS WORKING.. HERE IS WHAT I CAME UP WITH:


    <body onUnload="exit()">
    <a href="http://www.yahoo.com">testing</a>

    <SCRIPT language="JavaScript">
    <!--
    function exit() {
    var oldCookie = document.cookie;
    var number = 0;
    if (oldCookie.indexOf("counter=") < 0){
    number = 1;
    }else{
    number = oldCookie.charAt(oldCookie.indexOf("counter=")+ 8);
    number = parseInt(number) + 1;
    }
    if (number <= 1){
    var exp = new Date();
    var nowPlusOneDay = exp.getTime() + (12 * 60 * 60 * 1000);
    exp.setTime(nowPlusOneDay);



    document.cookie="counter=" + number + "; expires=" + exp.toGMTString();

    window.open('test.html','testing','location=0,menubar=0,toolbar=0,person albar=0,status=0,scrollbars=0,width=250,height=250');
    }
    }
    // End -->
    </SCRIPT>
    </body>


    Can you help me find a code that can meet my needs? It is essential that it pops up after they exit the page because I want them to be able to browse through the page before they provide feedback on it. I hope you understand what I mean. The purpose of the IP cookie is obviously to keep it from poping up again for that user. Your assistance in making the script above work is greatly appreciated. Thanks.


    Regards,

    Noble Varughese
    President of DesiBoyz Network
    http://www.elitehiphop.com
    Noble Varughese
    President of DesiBoyz Network
    http://www.desiboyz.net

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    SitePoint.com actually uses this exact technique, and it has been discussed in the following forum thread:

    http://www.sitepointforums.com/showt...?&postid=46968
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •