How can I disable all setTimeout events?

MonsterMMORPG picture MonsterMMORPG · Oct 2, 2010 · Viewed 58.6k times · Source

I am using ajax and asp.net. iI have a javascript function which creates many other javascript functions with setTimeout. After asynchronous postback happenes, I want to disable all of these setTimeouted events. How can I do that?

Answer

SeanDowney picture SeanDowney · Dec 1, 2011

If you can't get access to the code where the timer is set Nick's answer may not work, so all that I can think of is this hack.

It is a hack, use with caution!

// Set a fake timeout to get the highest timeout id
var highestTimeoutId = setTimeout(";");
for (var i = 0 ; i < highestTimeoutId ; i++) {
    clearTimeout(i); 
}

Basically it grabs the highest timer id and clears everything less than that. But it's also possible to clear other timers that you do not want to clear!