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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    popup once per browser session cookie not working

    Here's what I have:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function showRemote() {
    self.name = "main";
    
    var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
    "menubar=0,scrollbars=0,resizable=0,width=500,height=575";
    
    OpenWindow = window.open("popup_FebruaryWebPromo.html", "remote", windowprops);
    }
    
    showRemote()
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
          offset += search.length
          end = document.cookie.indexOf(";", offset);
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('poppedup')==''){
    showRemote()
    document.cookie="poppedup=yes"
    }
    }
    
    loadornot()
    
    //  End -->
    </script>

  • #2
    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
    Are you using this online, or on your computer??
    It memory serves me right, it will not work on your computer.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm developing on one computer, and looking on another. Besides, this cookie script "should" (or is supposed to be) per browser session. Either way, it's not working on the other computer.

    Can someone troubleshoot?

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your proggie isn't working coz it shouldn't work!
    Here are my 2 cents:

    [list=1][*]Go and read about the cookies, because if you want them to stay in the clients computer, you have to define the expiresvalue for each cookie and giving it a future date in GMT. So, the general syntax would look like this:
    Code:
    document.cookie = "newCookie=myVal; expires=a date in GMT"
    after doing this, then you could be sure that the cookie stays in the clients computer till the time expires or you delete it yourself ( by reseting the expires date)[*]Getting the cookies in this way ( using the indexOf function ) is a real torture! I would have recommend the split function. You could use it in this way:
    Code:
    myCookies = document.cookie.split("; "); // Note the space that I added after the semicolon in the split function, it SHOULD be there and you SHOULD put that space when you want to register a new cookie ( See the previous code, you see a space between the ; and the expires property
    cookieJar = new Array();
    for ( i=0; i<myCookies.length; i++)
    {
          cookieJar[i] = new Array();
          cookieJar[i]["name"] = myCookies[i].split("=")[0];
          cookieJar[i]["value"] = myCookies[i].split("=")[1];
    }
    [/list=1]

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First - AshleyQuick needs a "once per browser session". So we should not use the expires= tag. What is done is correct.

    Second - I saw a call to showRemote() right in the script - in addition to the call inside the loadornot fuction. So every time you refresh the page, the showRemote() will get called. Removing that call will fix it.

    Hope it helps.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe I'm wrong, but I think she wants to have that pop up page for any computer that didn't visit her page b4, right? So, to do this, we have to use the expires tag, that the next time that the same computer wants to view the page, we recognize it and do not show the pop up.
    And for calling the ShowRemote() function outside of loadornot(), you're right. I didn't see that!

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Removing showRemote() worked, thanks.

    Ash


  •  

    Posting Permissions

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