var timeleft = 5; var downloadTimer = setInterval(function(){ if(timeleft <= 0){ clearInterval(downloadTimer); window.location.href = WEB_URL } else { document.getElementById("countdown").innerHTML = timeleft; } timeleft -= 1; }, 1000);