Jason Jason - 1 year ago 107
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?

Answer Source

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(...);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download