I am pretty new to javascript. I have a little problem, I've looked this up and it seems like setInterval won't work at the "normal" speed if the tab is inactive. That needs to be solved.
Here is my code:
window.onload = function(){
function create() {
$.ajax({
url:"/includes/timer.php", //the page containing php script
});
}
//Start first time
var timez = <?php echo $server['newtime']; ?>;
var realtimez = <?php echo time(); ?>;
//Resetting
function reset() {
timez = <?php echo $server['newtime']; ?>;
realtimez = <?php echo time(); ?>;
}
setInterval(function(){
document.getElementById("timerz").innerHTML = timez - realtimez;
realtimez++;
if(realtimez > timez) {
create();
reset();
}
},1000);
}
Since I am pretty new to javascript, I can't seem to find a way to implement something that can check if the tab is inactive, and then speed up the interval to "normal" speed (1000ms).
Can somebody please help me doing it properly?
UPDATE: as I mentioned, I can't do it by myself. I've tried so many times. If somebody were to explain to me how to do it and try helping out with my code, then I would be very thankful.