0

I have this code below. I need to change the cookie to expire every hour, but setting 1 to this line doesn't help (tomorrow.setHours(6,0,0,0))

  // cookie
                var now  = new Date();
                var next = new Date(now.setTime(now.getTime() + sWait));
                document.cookie = cookie + '=1;expires=' + next.toGMTString() + ';path=/';
                var tomorrow = new Date(); tomorrow.setHours(6,0,0,0);
                document.cookie = cookie + 'Cap=' + (popsToday + 1) + ';expires=' + tomorrow.toGMTString() + ';path=/';
                pop2under();
            }
        };
gboffi
  • 22,939
  • 8
  • 54
  • 85
eazy
  • 23
  • 10

3 Answers3

0

you can find solution for this at How to set a cookie to expire in 1 hour in Javascript?

the solution is

var now = new Date();
var time = now.getTime();
time += 3600 * 1000 * 3;
now.setTime(time);
document.cookie = 
'username=' + value + 
'; expires=' + now.toUTCString() + 
'; path=/';
Community
  • 1
  • 1
Zain Aftab
  • 703
  • 7
  • 21
0

You can just change the line to the following:

tomorrow.setHours(tomorrow.getHours()+1);
Nick Vasic
  • 1,886
  • 1
  • 11
  • 6
0

Try this

if (document.cookie.indexOf('visited=true') == -1) {
    var onehour = 1000 * 60 * 60 * 1 * 1;
    var expires = new Date((new Date()).valueOf() + onehour);
    document.cookie = "visited=true;expires=" + expires.toUTCString();
    // your code
}
Anthony Carbon
  • 608
  • 1
  • 5
  • 18