views:

1476

answers:

2

I've got a setInterval() called in a jQuery plugin, but I want to clear it from my main page, where I don't have access to the variable that the setInterval was stored in.

Is there a way to clear all timers present on a page?

+5  A: 

No, you can't, not without the original variable.

musicfreak
+1  A: 

You can override setInterval:

window.oldSetInterval = window.setInterval;
window.setInterval = new function(func, interval) {
    var interval = oldSetInterval(func, interval);
    // store it in a array for stopping? stop it now? the power is yours.
}
Isaac Waller
I like this method. The next obvious function is onUnloadStopTimers. Consider it stolen. :)
Great Turtle