How do I set a cookie to expire after 1 minute or 30 seconds in Jquery?
var date = new Date();
date.setTime(date.getTime() + (30 * 1000)); //add 30s to current date-time 1s = 1000ms
$.cookie('username', username, { expires: date }); //set it expiry
For 1 minute, you can use:
var date = new Date();
date.setTime(date.getTime() + (60 * 1000));
$.cookie('username', username, { expires: date }); // expires after 1 minute
For 30 seconds, you can use:
var date = new Date();
date.setTime(date.getTime() + (30 * 1000));
$.cookie('username', username, { expires: date }); // expires after 30 second