我正在设置一个cookie来启动页面加载模式。 目前,模态只发生一次。设置Cookie到期时间
我需要它重置每个月,以便它不断弹出每个访问者每月一次。
是否有可能修改我的代码,使之发生或我需要以另一种方式做到这一点?任何帮助赞赏。
$(document).ready(function() {
//if cookie hasn't been set...
if (document.cookie.indexOf("ModalShown=true")<0) {
$("#newsletterModal").modal("show");
//Modal has been shown, now set a cookie so it never comes back
$("#newsletterModalClose").click(function() {
$("#newsletterModal").modal("hide");
});
document.cookie = "ModalShown=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
}
});
请小心使用['toGMTString()'](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toGMTString)此功能已弃用:'弃用 This功能已从Web标准中删除。尽管一些浏览器可能仍然支持它,但它正在被丢弃。不要在旧项目或新项目中使用它。使用它的页面或Web应用程序可能会随时中断。# – empiric
哦,很高兴知道谢谢@empiric :) –