Buggy IE6: clearTimeout does not work

quazzle
quazzle used Ask the Experts™
on
Hi!

did anyone experienced the following new "feature" of M$IE6: clearTimeout method of window object does not clear timeout. In 80% it does, but in 20 doesn't. Consider the following JScript example:

var TID = null;
function count(j) {
   if (j>20) alert("BUGGY IE");
   window.status = j++;
   self.TID = setTimeout("count(" + j + ")", 30);
}
function newcount() {
    if (self.TID) {
        clearTimeout(self.TID);
        self.TID = null;
    }
    count(0);
}
setInterval("newcount()", 100);

In example above function count is called 10 times per.sec. Each time the previos timeout is closed. In many browsers I tested it works and value of j never exceed 3. But in IE6 after a few seconds of running it exceeds 20 and raises the alert message.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Odd...

Would this clear it?

function newcount() {
self.TID = ""
   if (self.TID) {
       clearTimeout(self.TID);
       self.TID = null;
   }
   count(0);
}

Just a thought, but maybe it isn't recognising (self.TID) as true...  However, I don't have IE 6 so I can't test this.
if you remove the self. it works.... I suspect you need to reference self.TID as being either in newcount or in count... but not independent for both
Michel PlungjanIT Expert
Top Expert 2009

Commented:
quazzle,
No comment has been added lately (328 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between Alopederii http:#7470035 and kenny9336 http:#7470759

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

mplungjan
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial