为具有cookie的弹出窗口设置到期日期(和时间)

时间:2016-12-29 20:10:26

标签: javascript jquery cookies

我可以添加以下内容以防止在新年前夜晚上8点之后加载弹出窗口?

$(document).ready(function(){
    // Start Cookie for PopUp
    if (document.cookie.indexOf('colorframe=true') === -1) {
    var expires = new Date();
    expires.setDate(expires.getDate()+1);
    document.cookie = "colorframe=true; escKey=true; expires="+expires.toUTCString();

        // Start Popup
        setTimeout(function () {
            $.colorbox({
                escKey: true,
                html: '<a href="---"><img src="---" width="550" height="550" alt="New Years Eve at ---"/></a>'
            });
        }, 2000);
    };
});

1 个答案:

答案 0 :(得分:2)

您可以将当前时间戳与晚上8点的时间戳进行比较。使用http://www.epochconverter.com/我相信这是1483232400000。

$(document).ready(function(){
    // Start Cookie for PopUp
    if ((new Date).getTime() > 1483232400000) return;

    //remainder of code here

});

这假设您信任客户的计算机时间。