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 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    24
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Using clearInterval in body tag?

    Right now I have two functions that cycle through text and images using the setInterval method, called using onload in the body tag:

    Code:
    <body onload="var changeImg=setInterval ('cycleTools()',4000); 
    var changeTxt=setInterval ('cycleTxt()',16000);">
    Is there some way to use clearInterval with onunload without creating a specific function for it? A way similar to how I created setInterval with onload?

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    window onunload = "clearInterval('cycleText()')";

    But what is the point? If the page is unloaded then the setInterval function is automatically terminated.

    The Moving Finger writes; and, having writ,
    Moves on: nor all your piety nor wit
    Shall lure it back to cancel half a line,
    Nor all your tears wash out a word of it.

    -- Omar Khayyam

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    24
    Thanks
    5
    Thanked 0 Times in 0 Posts
    It's fine without in Chrome, but for some reason refreshing the page in Firefox doesn't reset the cycled text. The images reset and start from the beginning, but not the text that's cycling next to it, so they no longer match.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by taypandt View Post
    It's fine without in Chrome, but for some reason refreshing the page in Firefox doesn't reset the cycled text. The images reset and start from the beginning, but not the text that's cycling next to it, so they no longer match.
    That sounds like some problem with the script that causes the text cycling.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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