SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question JavaScript Popup Problem

    Hi,

    I have a Popup on my website which appears the first time someone leaves my home page. The problem is that it\'s intended for people who decided not to order, but it still appears when visitors go to my order page. Please can you tell me how to stop this happening, so that it only appears when people click away to a page other than my order page?

    The JavaScript code is shown below.

    Thank you.
    Joe Beaven



    <SCRIPT LANGUAGE=\'JAVASCRIPT\' TYPE=\'TEXT/JAVASCRIPT\'>
    <!--
    var win=null;
    function NewWindow(mypage,myname,w,h,pos,infocus){
    if(GetCookie(\"sid\") == \"999\"){return;}
    document.cookie=\"sid=999; Path=/; Expires= \" + getFuture(1);
    if(pos==\"random\"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    if(pos==\"center\"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
    else if((pos!=\'center\' && pos!=\"random\") || pos==null){myleft=0;mytop=20}
    settings=\"width=\" + w + \",height=\" + h + \",top=\" + mytop + \",left=\" + myleft + \" ,scrollbars=yes,location=no,directories=no,status=
    no,menubar=no,toolbar=no,resizable=no\";win=window.open(mypage,myname,settings);
    win.focus();}

    function getFuture(f){
    var d = new Date();
    d.setTime(d.getTime() + (86400000 * f));
    return d;
    }

    function GetCookie (name) {
    var arg = name + \"=\";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(\" \", i) + 1;
    if (i == 0) break;
    }
    return null;
    }

    function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (\";\", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }
    // -->
    </script>

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm going to presume people get to your order page via a link. And that you are firing the "NewWindow" function with the onUnload event handler.

    1) create a global var --> var isOrdering = false;
    2) reset it with the link -->
    <a href="".....onclick=doit()...>
    function doit()
    {
    url = 'orderpage.html';
    isOrdering = true;
    window.location = url;
    }
    3) check the var in the NewWindow function -->

    function NewWindow(mypage,myname,w,h,pos,infocus){
    if (isOrdering) return;

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •