开发者

How do I set cookies for individual pages for use with colorbox?

I have been using a script with colorbox that w开发者_C百科rites 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


I figured out how to do this:

I changed this line:

document.cookie = "visited=true; expires="+expires.toUTCString();

to this:

document.cookie = "visited=true; path=/page.php; expires="+expires.toUTCString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜