html - JavaScript refresh the page after few seconds -


i'm trying refresh page every 18 minutes javascript, code doesn't seem work.

here's code:

function startchecking() {     secondsleft -= 1e3;     if (secondsleft <= 3e4) {         document.getelementbyid("div_countdown").style.display = "";         document.getelementbyid("timercounter").innerhtml = math.abs(secondsleft / 1e3) + " seconds"     } }  function startschedule() {     clearinterval(timeout);     clearinterval(interval);     timeout = settimeout("window.location.href=window.location.href;", threshold);     secondsleft = threshold;     interval = setinterval(function() {         startchecking()     }, 1e3) }  function resettimer() {     startschedule();     document.getelementbyid("div_countdown").style.display = "none";     document.getelementbyid("timercounter").innerhtml = "" } var timeout, interval; var threshold = 108e4; var secondsleft = threshold; startschedule(); window.onload = function() {     startschedule() }  <a id="div_countdown" style="display:none;" onclick="javascript:resettimer();">chat refresh in <span id="timercounter"></span> click <font color="#fa5882">here</font> cancel</a> 

when go page wait 18 minutes if 30 seconds left refresh, display 30 seconds , count 0 when hits 0 refresh page , start again.

but when 30 seconds left , if clicked 30 seconds won't refresh reset timer 18 minutes.

i want make button, when click on it, button must hide , timer must stop session, until re-open browser. how able fix it?

the changes shorter delays (can't wait 18 minutes debug script).

in startchecking(), since show seconds left, should decrease value 1000 (1 second) , divide secondsleft 1000...

the interval should 1000.

that leaves 2 customizable numbers...
threshold 18 minutes max time...
, amount when show message in condition if (secondsleft <= 10000)

as quirimmo mentionned in comments, clearinterval() on timeout should cleartimeout().

function startchecking() {      secondsleft -= 1000;      if (secondsleft <= 10000) {          document.getelementbyid("div_countdown").style.display = "";          document.getelementbyid("timercounter").innerhtml = math.abs(secondsleft / 1000) + " seconds"      }  }    function startschedule() {      cleartimeout(timeout);      clearinterval(interval);      timeout = settimeout("window.location.href=window.location.href;", threshold);      secondsleft = threshold;      interval = setinterval(function() {          startchecking()      }, 1000)  }    function resettimer() {      startschedule();      document.getelementbyid("div_countdown").style.display = "none";      document.getelementbyid("timercounter").innerhtml = ""  }  var timeout, interval;  var threshold = 12000;  var secondsleft = threshold;  startschedule();  window.onload = function() {      startschedule()  }
<a id="div_countdown" style="display:none;" onclick="javascript:resettimer();">chat refresh in     <span id="timercounter"></span> click <font color="#fa5882">here</font> cancel  </a>

the page doesn't refresh in snippet above, in codepen


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -