Javascript stops executing in Firefox on a window move

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leehanson
    New Member
    • Mar 2008
    • 2

    #1

    Javascript stops executing in Firefox on a window move

    I have a timer function that displays to the user the current number of seconds left for the current question.

    It all works fine, however when the timer is ticking down, and the user starts to drag the window, it stops. It seems to entirely stop javascript from executing.

    This issue is not seen in IE. Can anyone explain why Firefox stops executing JS when the window is moved/mouse is down over the blue top of the firefox window.

    I pray that IE (microsoft) have not done something better than mozilla. It just can't be so it will crush my world

    :P

    Thanks hor your help,
    Lee

    ps. this is my first post, thanks for your help
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Welcome to TSDN.

    Even I have seen that issue, not even scripts but even an animated gif stops for a while.

    As a solution of your timer, instead of using setTimeout (which I think you would be) to add 1 second each time, use it to update the time by subtracting the starting time from the current time.

    Comment

    • leehanson
      New Member
      • Mar 2008
      • 2

      #3
      The code below is an example of the problem. copy and paste the below HTML & JS into an HTML document. Run the page and watch the timer count. Start moving around the firefox window and you will see that the timer stops incrementing.

      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script>
      var count = 0;
      function example()
      {
      count++;
      document.getEle mentById('examp le').innerHTML = count;

      var t = setTimeout("exa mple()",1000);

      }
      </script>
      </head>

      <body onload="example ()">
      <div id="example"></div>
      </body>
      </html>[/HTML]
      Last edited by acoder; Mar 5 '08, 06:58 PM. Reason: Added code tags

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [code=javascript]var startD = new Date();
        var startT = startD.getTime( );
        function example() {
        var nowD = new Date();
        var nowT = nowD.getTime();
        var count = Math.floor((now T - startT)/1000);
        document.getEle mentById('examp le').innerHTML = count;
        var t = setTimeout("exa mple()",1000);
        }[/code]

        Comment

        Working...