【问题标题】:jquery cookie - per site rather than per pagejquery cookie - 每个站点而不是每个页面
【发布时间】:2014-04-30 17:24:32
【问题描述】:

我们用fancybox构建了一个通知,需要向所有用户显示一次,但目前它在网站的每个页面上显示一次,并为访问者访问的每个页面设置一个cookie,我们的代码如下:

// jQuery Cookie popup
$(function() {
    if ($.cookie('cd-notification-cookie')) {
        // it hasn't been three days yet
    } else {
        $.fancybox.open([
            {
                href : '#notification'
            } 
        ], {
            maxWidth    : 420,
            maxHeight   : 800,
            fitToView   : false,
            width       : '90%',
            height      : 'auto',
            autoSize    : false,
            closeClick  : false,
            closeEffect : 'none'   
        });
      // set cookie to expire in 3 days
      $.cookie('cd-notification-cookie', 'true', { expires: 3});
    }
});

是否可以为整个网站而不是每页设置一个全局 cookie?

【问题讨论】:

    标签: jquery cookies jquery-cookie


    【解决方案1】:

    您可以尝试将路径设置为应用程序的基础,例如

    $.cookie('cd-notification-cookie', 'true', { expires: 3, path: '/'});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 2017-11-27
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多