2016-12-29 67 views
1

我可以在下面添加什么来防止在除夕晚上8点之后弹出窗口?为具有Cookie的弹出窗口设置到期日期(和时间)

$(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); 
    }; 
}); 
+0

根据当地时区或服务器的时区为晚上8点? – yts

+0

伟大的问题。格林威治标准时间5或EST ... – mdnash

回答

2

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

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

    //remainder of code here 

}); 

这是假设你信任你的客户的计算机上的时间。

+0

什么是更好,如果今晚在8我添加一个代码,说'48小时后不显示以下弹出'---我会怎么做? @yts – mdnash

+0

@mdnash我不认为这会更好。我认为这是理想的,如果你可以在渲染html时设置服务器时间检查(设置某种全局JavaScript变量),以便不依赖于客户的时间 – yts

+0

我可以从服务器时间辨别服务器的时间whois搜索?如果是的话,那么GMT ... – mdnash