View Full Version : Strange behavior with intervals
08-22-2010, 08:44 PM
I have an interval set that runs indefinitely (backgrounds switching) or until the viewer stops it. I've noticed that when I close a tab while it's running and revisit the page, it "doubles" the interval and the backgrounds get mixed up. Refreshing the page returns it to normal.
Does anyone know how to fix this?
I've tried clearing the interval with window.onunload and window.onbeforeunload. I'm thinking it has something to do with firefox not clearing its cache for the tab. I'll look into disabling that.
08-22-2010, 08:55 PM
Disabling cache did not fix it. :(
It seems to only be a problem with Firefox and Chrome... IE7 is fine but I haven't tried any other version.
08-22-2010, 08:57 PM
it sounds like a browser problem, not much you can do about it. if refreshing works you can try onload="window.location.reload() which should refresh the page.
08-22-2010, 09:02 PM
Wouldn't that cause infinite refreshing? ;)
08-23-2010, 04:29 AM
Well, I've changed everything back to recursive setTimeout calls and that fixed it... so it's definitely a problem with setInterval. I had even assigned each setInterval call to a global array and cycled through the array onunload clearing all intervals and the problem persisted. Regardless, using setTimeout calls with calculated timeout values is more efficient (i.e., it requires less processing) than using setInterval and clearing when a flag is raised. It still bothers me that the intervals weren't being cleared though hah...
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.