title: Create a countdown timer and redirect to another page after countdown comes to zero
body: <p>I want create a countdown timer for som sections of my asp.net sites with javascript. <br>
  The timer starts from various minutes or seconds. After countdown comes to zero, I want stop the timer tick and do somethings like redirect to another page.<br>
  I've found this code from google and it's ok, but never stop after countdown comes to zero. please help me to fix this bug.</p>
  
  <pre><code>&lt;head&gt;
  &lt;script&gt;
      function startTimer(duration, display) {
          var timer = duration, minutes, seconds;
          setInterval(function () {
              minutes = parseInt(timer / 60, 10)
              seconds = parseInt(timer % 60, 10);
  
              minutes = minutes &lt; 10 ? "0" + minutes : minutes;
              seconds = seconds &lt; 10 ? "0" + seconds : seconds;
  
              display.textContent = minutes + ":" + seconds;
  
              if (timer-- &lt; 0) {
                  //window.location = "http://www.example.com";
                  clearInterval(timer);
              }
          }, 1000);
      }
  
      window.onload = function () {
          var fiveMinutes = 60 * 5,
              display = document.querySelector('#time');
          startTimer(fiveMinutes, display);
      };
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;Registration closes in &lt;span id="time"&gt;05:00&lt;/span&gt;&lt;/div&gt;
      &lt;form id="form1" runat="server"&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>