简体   繁体   English

每天一次Javascript PopUp

[英]Javascript PopUp once per day

I have javascript popup it shows up per user (only once per day) and i need same popup but second.. when i try just to create second popup with same code it works like first one. 我有一个JavaScript弹出窗口,它显示每个用户(每天仅一次),我需要相同的弹出窗口,但是第二个..当我尝试使用相同的代码创建第二个弹出窗口时,它的工作原理与第一个类似。 if user saw first popup, he/she can't see other. 如果用户看到第一个弹出窗口,则他/她将看不到其他弹出窗口。 please help here is the code 请帮助这里的代码

 if (document.cookie.indexOf('_visited=1') == -1) { var delay_popup = 1000; setTimeout("document.getElementById('parent_popup').style.display='block'", delay_popup); var date = new Date; date.setDate( date.getDate() + 1 ); // Current date + 1 day document.cookie = '_visited=1; path=/; expires=' + date.toUTCString(); } 

I don't want them to work like 1 Popup 我不希望他们像1 Popup那样工作

I just had this problem today. 我今天刚遇到这个问题。

what i did is this 我做的是这个

enter code here


function readCookie(name) {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
            }


}


var myCookie = readCookie('daycookie');

if (myCookie=''){
   // code to show modal here 
   // then set an expiring token at midnight 
   var date = new Date();
   var midnight = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
   var x = Math.floor((Math.random() * 1000) + 1);
   document.cookie = 'daycookie' + "=" + x + "; " + "expires="+midnight;
}

the logic is at first if the cookie does not exist show the popup once the pop up shows it creates a cookie the expires at midnight and until next the day will the pop up show again. 逻辑是:如果cookie不存在,则首先显示弹出窗口,一旦弹出窗口显示它创建了cookie,它就会在午夜过期,直到第二天才会再次显示弹出窗口。

i hope this will help you. 我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM