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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How can I get a cookie to open pop-up window once only per session visit?

    A friend of mine gave me this bit of script, I spent hours and hours trying to get it working. He claims it works on his PC fine (WIN 2000 with IE6) but it don't work on mine (Win 95 IE4)

    The problem is:
    If the line if(document.cookie=="") is left as
    is, nothing happens and there is no cookie
    in the temp. internet files folder.

    If that line is changed to if(document.cookie!="")
    then the cookie appears in the temp. internet files
    folder OK, but the popup appears every time!

    Sorry if i'm being stupid but I haven't done much JavaScript...
    Cheers for any advice here.

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function openWindow(winfile)
    {
    window.open(winfile,'','resizable=yes,scrollbars=yes,toolbar=no,width=680,height=450')
    }
    function popUp()
    {
    expireDate=new Date
    expireDate.setSeconds(expireDate.getSeconds()+60)
    beenHere="hello"
    if(document.cookie=="")
    {
    window.open('popup.htm',"",'width=320,height=260')
    document.cookie="beenHere="+beenHere+";expires=" +expireDate.toGMTString()
    }
    }
    //-->
    </SCRIPT>

    </HEAD>

    <BODY TEXT="NAVY" BGCOLOR="#FFFFCC" LINK="BLUE" VLINK="PURPLE" ALINK="RED" onLoad=popUp()>

  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have attached a text file with a script for "popup once"

    Might be what you're after, works on my site.
    Attached Files Attached Files

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Mrs G,

    Your reply was appreciated. Downloaded the attachment 5 times (Doh!) before I worked out how to save the source on my Hdd.

    The code seems Mega more complex than the original, but then that is maybe the problem here with so many platforms and O/S out there... I will analyse and try it out tomorrow.

    As a footnote, the original script was given to me by a college tutor as part of an advanced web programming course - A friend and all but I still await a solution, cause it don't work as given!

    Blessu og tak fra Island
    Last edited by Spooky; 08-03-2002 at 02:09 AM.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    this is what I use....


    <html>
    <head>
    <title>PopUpScript</title>
    <script>
    function PopUp(PopUpUrl){
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((400)/2);
    placementy=(ScreenHeight/2)-((300+50)/2);
    WinPop=window.open(PopUpUrl,"","width=400,height=300,toolbar=0,location=0,directories=0,status=0,scr ollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screen Y="+placementy+",");
    }
    function CheckCookie(PopName) {
    var ReturnVal = "";
    var PopV = PopName + "=";
    if (document.cookie.length > 0) {
    OffSet = document.cookie.indexOf(PopV);
    if (OffSet != -1) {
    OffSet += PopV.length;
    End = document.cookie.indexOf(";", OffSet);
    if (End == -1)
    End = document.cookie.length;
    ReturnVal=unescape(document.cookie.substring(OffSet, End));
    }
    }
    return ReturnVal;
    }
    function LOadIt(){
    if (CheckCookie("Popped")==""){
    PopUp('http://www.A1ien51.8k.com');
    document.cookie="Popped=yes";
    }
    }
    </script>
    </head>
    <body onload="LOadIt()">
    </body>
    </html>



    this code can be generated on here: http://www10.brinkster.com/A1ien51/s...UpWinGenV3.htm
    A1ien51

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried the script you posted above and nothing happens.

    This is because there are no cookie functions

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Spooky if you want to use session only cookies as indicated by your topic, then you don't need to expire the cookie. It will last until the end of the session. The following should work just fine provided there are no other cookies from that domain:

    function popUp(){
    var beenHere="hello"
    if(document.cookie==""){
    window.open('popup.htm',"",'width=320,height=260')
    document.cookie="beenHere="+beenHere;
    }
    }

    If there are other cookies then document.cookie obviously won't be empty and you'll need to check for that specific cookie instead. Post back if you still have problems.

  • #7
    New Coder
    Join Date
    Jul 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With other cookies:

    <script type="text/javascript" language="JavaScript">
    getCookie = document.cookie;
    function getTag(name) {
    index = getCookie.indexOf(name + "=");
    if (index == -1) return null;
    startVal = getCookie.indexOf("=", index) + 1;
    finishVal = getCookie.indexOf(";", startVal);
    if (finishVal == -1) finishVal = getCookie.length;
    return unescape(getCookie.substring(startVal, finishVal)); }
    if (!getTag("firstVisit")) {
    window.open('popup.htm',"",'width=320,height=260');

    document.cookie = "firstVisit=true";
    }

    </script>

  • #8
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all,

    My thanks also to Alien51, boywonder and Pooh for their suggestions. They will all be tried for an effective solution on my little community (charity) site.

    So far Mrs G's solution works out (but I'm working on the timer as it's not quite right for me...) Just a shame the original short script don't work!

    Cheers from JavaScript newbie!

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Explain your timer requirements


  •  

    Posting Permissions

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