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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question clearTimeout Loop Lags IE, but not FF

    Hey everyone, I have a question and hope for a answer.

    On one of my pages, I have 5 timers running off setTimeouts

    But I refresh the Timers every 2 seconds OR 10 seconds. (depending on the browser)

    My problem lies in with, when I loop to clear them.

    I did a alert and got a number around 844019
    Code:
    alert(totalTimers);
    totalTimers is set at the timeouts,
    Code:
    totalTimers = setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
    and here is the loop to clear the timers,

    Code:
    tlc=0;
    while(tlc < totalTimers){
    	clearTimeout(tlc); 
    	tlc=tlc+1;
    }
    Is there a way to clear All Timers at once?

    That way IE wont lag and ask to stop script because of how many loops it has to run through?

    Firefox & Safari work fine.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    My understanding of javascript tells me that there is only one variable called totalTimers so that there must be only one clearTimeout(totalTimers) command to stop it. What is that loop for? you clearTimeout() a number? Don't confound the variable, as an object, with its value.

    And use an anonymous:
    Code:
    totalTimers = setTimeout(function(){displayTZCountDown(countdown-1,tzcd)},999);
    ...
    //to stop it:
    clearTimeout(totalTimers);
    Last edited by Kor; 05-16-2009 at 07:08 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the timers are reloaded (without clearing the old timers) into a DIV because for each product it has its own countdown timer until sale ends.

    The timers get reloaded because it is a auction website that checks the DB for changes to the product, its timer, and its price.

    So if I dont clear the timer, it will switch between the timer that loaded on page entrance and the timer that gets reloaded.

    The website I am working on this for is a auction website

    So what your saying is all I would need to put is
    PHP Code:
    clearTimeout(totalTimers); 
    and it should work?

    And then there is that LAG/Glitch in IE that wont show new information (changes to the page) unless you refresh 10 times or reopen IE and go back to the page.


  •  

    Posting Permissions

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