尝试检查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设置上的额外设置,不工作。
answer需要以下脚本来运行:
$(document).ready(function () {
if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null) {
// Reveal modal
$("#myModal").reveal();
// Set Cookie on click
var ageVerificationBtn = document.getElementById('ageVerification');
ageVerificationBtn.addEventListener('click', function (event) {
$.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', {
expires: 10, //expires in 10 days
});
$('#myModal').hideModal()
});
}
});