Question

JS:

$(document).ready(function() {
  var check_cookie = $.cookie('the_cookie');
  if(check_cookie == null){
    $.cookie('the_cookie', 'the_value', { expires: 30 * 60 * 1000 });
    $("#hidden_link").fancybox().trigger('click');
  }   
});

It works. I want change to expires time to 3 days. How can I fix it?

Was it helpful?

Solution

Try this, you can pass a date

var date = new Date();
date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
$.cookie("the_cookie", "the_value", { expires: date });

or send the days as parameters

$.cookie('the_cookie', 'the_value', { expires: 3 });

Output

if you run the function in browser console where jquery cookie is already present as source, in both the cases it prints

"the_cookie=the_value; expires=Mon, 30 Dec 2013 08:28:36 GMT"

(current time is Mon, 27 Dec 2013 08:28:36 GMT)

OTHER TIPS

Try like this,

$(document).ready(function() {
  var check_cookie = $.cookie('the_cookie');
  if(check_cookie == null){
    $.cookie('the_cookie', 'the_value', { expires: time()+3600*24*3 });
    $("#hidden_link").fancybox().trigger('click');
  }   
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top