如何为与 colorbox 一起使用的各个页面设置 cookie?
我一直在使用带有 colorbox 的脚本,该脚本在访问页面时写入 cookie,并且仅在上个月未访问该页面时才在页面加载时打开 colorbox。
我现在想修改它,以便它为特定页面而不是整个域写入和检查 cookie。这是因为我每个月都会发布一个新页面,并且希望用户每月第一次访问新页面时打开一个颜色框。这是目前的脚本:
if (document.cookie.indexOf('visited=true') === -1) {
var expires = new Date();
expires.setDate(expires.getDate()+31);
document.cookie = "visited=true; expires="+expires.toUTCString();
$.colorbox({href:'welcome.html', width:"60%", speed:1500});
}
有人可以帮我调整它以逐页工作吗,
谢谢,
尼克
I have been using a script with colorbox that writes a cookie when a page is visited and only opens the colorbox on page load if the page has not been visited in the last month.
I would now like to amend this so that it writes and checks for a cookie for the specific page rather than the domain as a whole. This is because I am publishing a new page each month and would like a colorbox to open the first time a user visits the new page each month. Here is the script as it currently stands:
if (document.cookie.indexOf('visited=true') === -1) {
var expires = new Date();
expires.setDate(expires.getDate()+31);
document.cookie = "visited=true; expires="+expires.toUTCString();
$.colorbox({href:'welcome.html', width:"60%", speed:1500});
}
Could someone help me adapt this to work on a page-by-page basis,
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了如何做到这一点:
我将此行:更改
为:
I figured out how to do this:
I changed this line:
to this: