I am calling a method in Javascript every 1 sec using setInterval, when google tab is inactive this function is not called or slows down. This function is for timer countdown, even when Tab is inactive I want setInterval to call my function every 1 sec. I have seen similar questions and answers here in this forum, but those solutions did not work for me. I am fairly new to using Javascript. Here's my code:
<div id ="clock"/>
self.setInterval("timer()",1000);
var timeSpentSecs = 0;
var timeLimit = 300000;
function timer()
{
var timeLeft = timeLimit - timeSpentSecs;
var timeLeftHour = Math.floor(parseInt(timeLeft)/3600);
timeLeft = timeLeft % 3600;
var timeLeftMin = Math.floor(parseInt(timeLeft)/60);
var timeLeftSec = timeLeft % 60; timeSpentSecs++;
document.getElementById("clock").innerHTML = "<B>" + ' Timeleft ' + timeLeftHour + ' :' + timeLeftMin + ' :' + timeLeftSec + "</B>";
}