Reload page with Javascript when count down reaches 0 -
i m using below function display count down , reload page when counter reaches 0. sat , watched counter hit 0 , nothing happened. isn't location.reload()
suppose refresh page?
function secondpassed() { var numdays = math.floor(seconds / 86400); var numhours = math.floor((seconds % 86400) / 3600); var numminutes = math.floor(((seconds % 86400) % 3600) / 60); var numseconds = ((seconds % 86400) % 3600) % 60; if (numseconds < 10) { numseconds = "0" + numseconds; } document.getelementbyid('count').innerhtml = "<span class='fa fa-clock-o' aria-hidden='true'></span> " +('' + numdays).slice(-2) + "d " + "" +('' + numhours).slice(-2) + "h " + "" + ('' + numminutes).slice(-2) + "m " + "" +('' + numseconds).slice(-2) + "s "; if (seconds <= 0) { clearinterval(countdowntimer); location.reload(); } else { seconds--; } } setinterval(function () { secondpassed(); }, 1000);
i promoted comment answer describing issue.
your countdowntimer
undefined when trying clearinterval
, hence reload
not called because execution aborted.
just remove offending clearinterval
, work.
if (seconds <= 0) { // >> clearinterval(countdowntimer); location.reload(); } else { seconds--; }
Comments
Post a Comment