Skip to main content

Before redirecting a request, display a message with a countdown.

<html>
<head>
  <title>Redirecting to...</title>

  <style type="text/css">
    * { text-align: center; }
  span {font-weight: bold; }
  </style>
</head>
<body>

  <h1>Redirecting to...</h1>
  <p><a href="http://google.com/">http://google.com/</a></p>
  <p>in <span id="seconds"></span> seconds</p>

  <script type="text/javascript">

  window.onload = function () {

    var count = 3; // 3-seconds

    var secondsEl = document.getElementById('seconds');
    secondsEl.innerHTML = count;

    var counter = setInterval(timer, 1000);

    function timer() {
      count = count - 1;

      if (count <= 0) {
        clearInterval(counter);

        secondsEl.innerHTML = 0;
        window.location = "http://google.com/";

        return;
      }
      secondsEl.innerHTML = count;
    }

  };

  </script>
</body>
</html>