Web Analytics Made Easy -
StatCounter Set Cookie for browser session only - CodingForum

Announcement

Collapse
No announcement yet.

Set Cookie for browser session only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Cookie for browser session only

    Greetings,
    What do I need to change here so that when the popup loads it will not reload when a visitor returns to the page during a visit. I want it to load the next time they start a new session.

    TIA and regards...
    Walt...


    function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {
    begin = document.cookie.indexOf(NameOfCookie+"=");
    if (begin != -1) {
    begin += NameOfCookie.length+1;
    end = document.cookie.indexOf(";", begin);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(begin, end));
    }
    }
    return null;
    }

    function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

    document.cookie = NameOfCookie + "=" + escape(value) +
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
    }

    function delCookie (NameOfCookie) {
    if (getCookie(NameOfCookie)) {
    document.cookie = NameOfCookie + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    }

    function DoTheCookieStuff()
    {
    visited=getCookie('visited');
    if (visited==null)
    {
    setCookie('visited','yes',365)
    MyWindow=window.open('http://www.c-spotco.com/weather_page.htm','MyWindow','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollb ars=yes,resizable=yes,width=640,height=480,left=1,top=1');
    }
    }

  • #2
    function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));


    document.cookie = NameOfCookie + "=" + escape(value) +
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())
    ;
    }

    try getting rid of the parts in bold. that should do it, but i'm tired, and didn't take a real thorough look.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Thank you joh6nn.

      I did as you suggested but still now joy.

      I also deleted this line:
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";

      also with no luck. Have you another suggestion?
      I'll keep trying too....

      Regards...

      Comment


      • #4
        Not sure if this helps

        Take a look here:
        http://wsabstract.com/popwin/index.shtml

        Step 3 has a once only per browser session.

        Comment


        • #5
          Thank you jtr, just right!!!

          Regards....

          Comment

          Working...
          X