fourr
fourr

Reputation: 59

Change the cookie experation time to 5 minutes

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();
    }
});

Upvotes: 0

Views: 220

Answers (2)

Al.G.
Al.G.

Reputation: 4387

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 });

Upvotes: 0

raina77ow
raina77ow

Reputation: 106443

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 });

Upvotes: 1

Related Questions