Title

JS countdown + forward to url

description

Forward a visitor of a page to another url x time after landing, and show the countdown

Published 2022-08-11

Modified 2022-08-19

content

See it in action on mamotok.org (you will be redirected back to ronaldpostma.com homepage)

				
					<script>
    var time = 15;
setInterval(function() {
  var seconds = time % 60;
  var minutes = (time - seconds) / 60;
  if (seconds.toString().length == 1) {
    seconds = "0" + seconds;
  }
  if (minutes.toString().length == 1) {
    minutes = "0" + minutes;
  }
  document.getElementById("time").innerHTML = minutes + ":" + seconds;
  time--;
  if (time == 0) {
    window.location.href = "https://www.ronaldpostma.com/";
  }
}, 1000);
</script>

<div class="timer" onload="timer(20)">
  <div class="time">
  You will be redirected in <span id="time">'loading...'</span> seconds.
  </div>
</div>
				
			

Sources & References