jQuery(document).ready(function(){
if (document.cookie.indexOf('visited=true') === -1) {
var expires = new Date();
expires.setDate(expires.getDate()+30);
document.cookie = "visited=true; path=/; expires="+expires.toUTCString();
jQuery.colorbox({open:true,href:"<?=home_url()?>/popup/?site_type=2",iframe:true, innerWidth:"700px", innerHeight:"410px"});
}
});
此 cookie 在我关闭浏览器时过期,但我希望它持续 30 天,直到他们再次看到弹出窗口。
最佳答案
不使用 expires
,尝试使用 max-age
(以秒为单位)。这不涉及创建和修改 Date
实例。
if (document.cookie.indexOf('visited=true') === -1) {
document.cookie = "visited=true; path=/; max-age=2592000;";
关于javascript - 我的 Javascript cookie 在 session 时过期,而不是 30 天后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10305647/