Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts

    Strange behavior with intervals

    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.

  • #2
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    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.

  • #4
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    Wouldn't that cause infinite refreshing?

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •