【问题标题】:Cookie code not workingCookie 代码不起作用
【发布时间】:2013-12-31 20:56:46
【问题描述】:

我正在尝试使用 jquery ui 和 cookie 设置一个模式弹出窗口,当用户访问该站点时,它只会在主页上打开一个弹出窗口。下面是我的代码

$(document).ready( 
function () {
if (($.cookie('visited') === null)|| ($.cookie('visited') === undefined )) {
 $(function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      width:700,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      },
      show: {
    effect: "blind",
    duration:500
  },
  hide: {
    effect: "blind",
    duration: 500
  }
    });
  });

$.cookie('visited') = 'visited';
}

else if($.cookie('visited') === 'visited')  {
alert('its here ');
return false;

}


});

我知道模态代码正在运行,但我不知道为什么 cookie 代码不起作用。

它在 JSBIN 上运行良好,但在我希望它运行的站点上运行不正常。这是它应该运行的 site

【问题讨论】:

    标签: javascript jquery cookies


    【解决方案1】:

    尝试从 if: 中删除 $(function())

    $(document).ready(function () {
        if (($.cookie('visited') === null)|| ($.cookie('visited') === undefined )) {
            $( "#dialog-message" ).dialog({
            ...
    

    【讨论】:

    • 不起作用,我认为这与我的问题没有任何关系
    • 好的,然后尝试通过调用 $.cookie('visited', 'visited') 来设置 cookie
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多