I cannot get this to redirect. The timer works but it doesn't go anywhere. I need this to redirect to another webpage

20 Views Asked by At
<script>
function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    var end =setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        if (--timer < 0) {
            //window.location = "http://www.YouTube.com";
            clearInterval(end);
        }
    }, 1000);}

window.onload = function () {
    var fiveMinutes = 5,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};
</script>
</head>
<body>
<div>Redirect in <span id="time">05:00</span></div>
<form id="form1" runat="server">

</form>

I cannot get this to actually redirect. the countdown works but it doesn't redirect. I just get the timer. the timer counts down and hits zero and it goes absolutely nowhere.

1

There are 1 best solutions below

0
jcommando On

Firstly, --timer will always return 4 since 5 was set as the initial value, thus you will never be redirected. You should add a else block to reduce timer value by 1 after every 60 000 milliseconds.