0

I try to redirect a user to another page after X seconds have passed, this is my attempt, but i get a error page and can't do anything:

enter image description here

 <span id="zeit"></span>

 <script>
     var timer=9;
     while (timer>0) {

        setTimeout(function(){
            timer = timer - 1;
            document.getElementById("zeit").innerHTML = timer;

        },1000);
    }

    window.location.href = "home";
</script>

What am I doing wrong?


Solution:

var timer=9;

setInterval(function(){
    timer = timer - 1;
    document.getElementById("zeit").innerHTML = timer;

    if (timer===0) window.location.href = "home";

},1000);
Black
  • 18,150
  • 39
  • 158
  • 271

0 Answers0