Jason Jason - 7 months ago 52
Javascript Question

Resetting a setTimeout

I have the following:

window.setTimeout(function() {
window.location.href = 'file.php';
}, 115000);

How can I, via a .click function, reset the counter midway through the countdown?


You can store a reference to that timeout, and then call clearTimeout on that reference.

// in the example above, assign the result
var timeoutHandle = window.setTimeout(...);

// in your click function, call clearTimeout

// then call setTimeout again to reset the timer
timeoutHandle = window.setTimeout(...);