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
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts

    overlapping setTimeout

    I have a function that calls itself every 2 min via setTimeout to reload a frame. However, action by the user may change that frame 1 min into the timer, therefore running that function again, and therefore setting the timer again.

    So does that mean that i'm going to get overlapping setTimeouts? If so, there any way i can cancel any timers put on a certain function before running it again?
    If I'm postin here, I NEED YOUR HELP!!

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    If you store the timeout in a variable, you can clear it like this:
    Code:
    var
        timeout=setTimeout(oogle,boogle);
    
    /- - -/
    
    if(shouldClearTimeOut)
        clearTimeout(timeout);
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    THough its not fatal, Firefox complains when doing a clearTimeout on a setTimeout that hasn't started yet. Anything i can do to stop it from complaining?

    THanks BTW.
    If I'm postin here, I NEED YOUR HELP!!

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    if (timeout) clearTimeout(timeout);
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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