Hello everyone I am new to JavaScript and I want to have a countdown that automatically starts when the page loads, and only resume if the page is focused. Here is an example http://hp30405.pythonanywhere.com/mz7z5/
.
How can I use this same logic in setTimeout(function() {});
?
This is my script:
$(window).load(function() {
var timeleft = 20;
var downloadTimer = setInterval(function() {
document.getElementById("timer").innerHTML = timeleft;
timeleft -= 1;
if (timeleft < 0) {
clearInterval(downloadTimer);
document.getElementById("timer").innerHTML = "20 sec done";
}
}, 1000);
setTimeout(function() {
$("#submit").removeAttr("disabled");
}, 22000);
});