How can I disable all setTimeout events?

前端 未结 4 1831
清酒与你
清酒与你 2020-12-12 12:12

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 dis

4条回答
  •  伪装坚强ぢ
    2020-12-12 12:54

    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!

提交回复
热议问题