对于在午夜到期的cookie的代码Javascript

 丁军东建宏 发布于 2023-02-09 11:12

我有一个带有cookie的弹出窗口,它会在一天(24小时)内到期,我希望这个cookie每天午夜到期(所以弹出窗口显示你每天第一次进入网络).我不是程序员,所以,请问有人可以告诉我在代码中需要更改的内容吗?我已经阅读了一些问题的解决方案,但我不知道如何实现它.

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
if ($.cookie("anewsletter") != 1) { 
//centering with css
centerPopup();
//load popup
loadPopup(); 
}     
//CLOSING POPUP
//Click the x event!
$("#popupContactClose").click(function(){
disablePopup();
$.cookie("anewsletter", "1", { expires: 1 });
});

//Click the bacground!
$("#backgroundPopup").click(function(){
disablePopup();
$.cookie("anewsletter", "1", { expires: 1 });
});


//Press Escape event!
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
    disablePopup();
    $.cookie("anewsletter", "1", { expires: 1 });
}
});

});

非常感谢你!

1 个回答
  • $.cookie可以将日期作为expires值,因此您可以使用以下内容

    var midnight = new Date();
    midnight.setHours(23,59,59,0);
    
    $.cookie('anewsletter', '1', { expires: midnight });
    

    2023-02-09 11:15 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有