PDA

View Full Version : Pop up Caller



agungbudiono
11-01-2016, 12:25 PM
I have a script that serves as a caller for pop up ads. I want to develop this sript so it only works 12 hours a day (or we can set the time). Anyone can help?


<script>
document.addEventListener('DOMContentLoaded', function() {
if(typeof getCookie('popup-schedule-chuan') == 'undefined'){


setCookie('popup-schedule-chuan' , 'true' , 1);
setTimeout(function(){
document.getElementById("xDialog").style.opacity = "1";
} , 5000);
}
});

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
</script>

jscheuer1
11-01-2016, 04:32 PM
Perhaps like so, which would stop this happening from 8am till 8pm local time of the user visiting the page:


<script>
document.addEventListener('DOMContentLoaded', function() {
var limit1 = 8, limit2 = 20, hour = new Date().getHours();
if(hour >= limit1 && hour < limit2){return;}
if(typeof getCookie('popup-schedule-chuan') == 'undefined'){


setCookie('popup-schedule-chuan' , 'true' , 1);
setTimeout(function(){
document.getElementById("xDialog").style.opacity = "1";
} , 5000);
}
});

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
</script>

NOTE: The hours for the limits are in 24 hour notation. The limit2 value is 20, which is 8pm. Once the hour advances to 20 (8pm) the code will run again. So essentially stops at 8am and resumes at 8pm. Other values may be used for the limit1 and limit2 vars if desired.