我正在尝试使用 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 上运行良好,但在我希望它运行的站点上不起作用。这是它应该工作的网站。
尝试从if中删除$(function()):
$(document).ready(function () {
if (($.cookie('visited') === null)|| ($.cookie('visited') === undefined )) {
$( "#dialog-message" ).dialog({
...