title: countdown timer reloading again on refreshing
body: <p>countdown timer code in javascript. But it is restarting again when the page is refreshed. I want the timer should continue even though it is restarted.</p>
  
  <p>Help me to deal with this problem as i am beginner this is my first application i need some detail inputs from you.</p>
  
  <pre><code>`
  &lt;body&gt;
  &lt;div id="divCounter"&gt;&lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  
  var hoursleft = 0;
  var minutesleft = 35;           // you can change these values to any value greater than 0
  var secondsleft = 0;
  
  var finishedtext = "Countdown finished!" // text that appears when the countdown reaches 0
  var end = new Date();
  
  end.setMinutes(end.getMinutes()+minutesleft);
  end.setSeconds(end.getSeconds()+secondsleft);
  
  
  if(localStorage.getItem("counter")){
  
      var value = localStorage.getItem("counter");
  
  }else{
    var value = 0;
  }
  
  
  var counter = function (){
  
  
      var now = new Date();
  var diff = end - now;
  diff = new Date(diff);
  
  var sec = diff.getSeconds();
  var min = diff.getMinutes();
  
  if (min &lt; 10){
      min = "0" + min;
  }
  if (sec &lt; 10){
      sec = "0" + sec;
  }
  
  if(now &gt;= end){
      clearTimeout(timerID);
      document.getElementById('divCounter').innerHTML = finishedtext;
  }
  else{
      var value = min + ":" + sec;
  //document.getElementById('divCounter').innerHTML = min + ":" + sec;
  localStorage.setItem("counter", JSON.stringify(value));
  }      
  
   // timerID = setTimeout("cd()", 1000);
  // value = JSON.parse(localStorage.getItem("counter"));
  //$('#divCounter').append(value);
  document.getElementById('divCounter').innerHTML = value; 
   }
  
  
  
  
  
   var interval = setInterval(function (){counter();}, 1000);
   &lt;/script&gt;
   &lt;/body&gt;
   `
  </code></pre>