var time = document.getElementById('time'); var second = time.innerHTML; setInterval(function(){ time.innerHTML = second--; if(second == 0){ window.location.href = "/"; } }, 1000);