Organizational Research By

Surprising Reserch Topic

How do you setup a cookie which expires after 5mins in jquery?



asked May 20, 2015 in JAVASCRIPT by rahulgii
0 votes
22 views



Related Hot Questions

3 Answers

0 votes

For 5 mins you need to modify it to : -

var date = new Date();
date.setTime(date.getTime() + (5 * 60 * 1000));
$.cookie("example", "foo", { expires: date });

You have set it to 30 minutes now.

answered May 20, 2015 by rahulgii
0 votes
var expires = new Date();
expires.setMinutes( expires.getMinutes() + 5 ); // Create a date 5 minutes from now

// The path parameter is needed to make this cookie valid across the whole page
$.cookie('login_id', 'cafed00d', {expires: expires, path: '/'});

To destroy said cookie:

$.cookie('login_id', null);
answered May 20, 2015 by rahulgii
0 votes
{expires: date}

where date is a date object. In your case you should do (for 5 minutes):

var date = new Date();
date.setTime(date.getTime() + (5 * 60 * 1000));
answered May 20, 2015 by rahulgii

...