【问题标题】:How to change expiry time in cookie settings for fancybox ?如何更改 fancybox cookie 设置中的到期时间?
【发布时间】:2013-12-27 16:47:27
【问题描述】:

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

它有效。我想将过期时间更改为 3 天。我该如何解决?

【问题讨论】:

  • 这是一道简单的数学题吗?
  • 您使用的是什么版本?从 wiki 页面,只需要这样指定: $.cookie('the_cookie', 'the_value', { expires: 3 }); 3天。

标签: jquery cookies fancybox jquery-cookie


【解决方案1】:

试试这个,你可以传递一个日期

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

或将日期作为参数发送

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

输出

如果您在 jquery cookie 已经作为源存在的浏览器控制台中运行该函数,则在这两种情况下都会打印

"the_cookie=the_value; expires=2013 年 12 月 30 日星期一 08:28:36 GMT"

(当前时间为 2013 年 12 月 27 日星期一 08:28:36 GMT)

【讨论】:

    【解决方案2】:

    这样试试,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      相关资源
      最近更新 更多