0

I have a cookiescript, works great. I would like to have the experation time after 5 minutes. How can I do this?

expires: 30 = 30 days?

EDIT

cookie_popup = (function() {

    var date = new Date();
    var minutes = 5;
    date.setTime(date.getTime() + (minutes * 60 * 1000));

    if ($.cookie('cookie_popup') == undefined) {
        $('.cookie-popup-wrap').fadeIn(600);
        $.cookie('cookie_popup',true,{ expires: date });
    };

    $('#closepopup').click(function (e) {
        e.preventDefault();
        $('.cookie-popup-wrap').fadeOut(600);
    });
});

setTimeout(function() {
    cookie_popup();
}, 2000);

$(window).scroll(function(){
    if($(this).scrollTop() > 100){
        cookie_popup();
    }
});
Community
  • 1
  • 1
fourr
  • 59
  • 1
  • 9

2 Answers2

1

It's said in $.cookie documentation:

expires:

Define lifetime of the cookie. Value can be a Number which will be interpreted as days from time of creation or a Date object. If omitted, the cookie becomes a session cookie.

So you'll have to pass Date object there. For example:

var expireDate   = new Date();
var minutesToAdd = 5; 
expireDate.setMinutes(expireDate.getMinutes() + minutesToAdd);
$.cookie('cookie_popup', true, { expires: expireDate });
raina77ow
  • 103,633
  • 15
  • 192
  • 229
0

Possible dublicate: How to expire a cookie in 30 minutes using jQuery?

var date = new Date();
var minutes = 5;
date.setTime(date.getTime() + (minutes * 60 * 1000));
$.cookie("example", "foo", { expires: date });
Community
  • 1
  • 1
Al.G.
  • 4,327
  • 6
  • 31
  • 56