Search code examples
javascripttimeout

javascript: Clear all timeouts?


Is there a way to clear all time outs from a given window? I suppose the timeouts are stored somewhere in the window object but couldn't confirm that.

Any cross browser solution is welcome.


Solution

  • They are not in the window object, but they have ids, which (afaik) are consecutive integers.

    So you may clear all timeouts like so:

    var id = window.setTimeout(function() {}, 0);
    
    while (id--) {
        window.clearTimeout(id); // will do nothing if no timeout with id is present
    }