The setTimeout is only executed 1 time. If you want it to be uninterrupted, exchange for setInterval.
Now a problem arises: as the cycle is run every 3 seconds, it will re-load the page every 3 seconds when the minute meets one of the conditions of the if. What you can do is create a localStorage to store the value of the minute so that Reload only occurs 1 time, and put one more condition in the if checking if the localStorage is different from the current minute, and including the conditions || in parentheses ():
$(document).ready(function () {
// Handler for .ready() called.
window.setInterval(function () {
var data = new Date();
var minute = data.getMinutes();
if((minute == 15 || minute == 20 || minute == 45 || minute == 0) && localStorage.getItem("reload") != minute){
localStorage.setItem("reload", minute);
setTimeout(function(){
location.href = "teste.html";
}, 500);
}
}, 3000);
});
See that I used a setTimeout before reloading the page so that no
there are problems in creating localStorage (although I’ve seen comments from
that the localStorage is synchronous, but I’m not sure and I found no documentation about it).
What you’ve tried to do?
– LeAndrade
I’m editing.
– Leandro Kojima
I do not know who had commented here ""Trade by setInterval", it worked! Thanks!
– Leandro Kojima