【发布时间】:2014-06-24 21:40:19
【问题描述】:
尝试检查 cookie 是否存在。如果没有,则启动基础显示模式。单击模态框上的按钮设置一个新的 cookie,以便下次加载页面时不会加载模态框。
我设法设置了 cookie,但我的检查似乎不起作用,因为即使 cookie 在我的浏览器历史记录中,我的模式框也会出现。
$(document).ready(function () {
if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null || $.cookie('ageVerification') != 'Verification that user is over the legal drinking age in your country') {
// Reveal modal
$("#myModal").reveal();
// Set Cookie on click
var ageVerification = document.getElementById('ageVerification');
ageVerification.addEventListener('click', function (event) {
$.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', {
expires: 10, //expires in 10 days
path: '/', //The value of the path attribute of the cookie
//(default: path of page that created the cookie).
domain: 'becketts.knibbshost.co.uk', //The value of the domain attribute of the cookie
//(default: domain of page that created the cookie).
secure: true //If set to true the secure attribute of the cookie
//will be set and the cookie transmission will
//require a secure protocol (defaults to false).
});
$('#myModal').hideModal()
});
}
});
【问题讨论】:
-
您的 cookie 实际上并没有被设置在首位 becketts.knibbshost.co.uk
-
在您的 cookie 检查中取出最后一个“或”语句。如果它有效,那么字符串比较中可能缺少一些东西,可能是结束标点符号 (.)?
标签: javascript jquery cookies jquery-cookie zurb-reveal