Reply
Firefox freezes and stops responding IE doesnt
Old 10-15-2008, 07:33 PM Firefox freezes and stops responding IE doesnt
Junior Talker

Posts: 1
I have a javascript which creates a live clock which works fine but after a while in FF the browser hangs and stops responding then I have to close the program with ctrl alt del.

When i remove the script it never happens, and it works perfectly fine in IE with the script just not FF.

Was wondering if any expert here might know what I did wrong?

Hope you can help!

Code:
function live_clock()
     {
         var today  = new Date();
         var second = today.getSeconds();
         var minute = today.getMinutes();
         var hour   = today.getHours();
         var hour24 = today.getHours();
         var ampm   = "";
         
         var day    = today.getDay();
         var date   = today.getDate();
         var month  = today.getMonth();
         var year   = today.getFullYear();
         
         var days   = new Array();
          days[0]   = "Sunday";
          days[1]   = "Monday";
          days[2]   = "Tuesday";
          days[3]   = "Wednesday";
          days[4]   = "Thursday";
          days[5]   = "Friday";
          days[6]   = "Saturday";
          
         var mns   = new Array();
          mns[0]   = "January";
          mns[1]   = "February";
          mns[2]   = "March";
          mns[3]   = "April";
          mns[4]   = "May";
          mns[5]   = "June";
          mns[6]   = "July";
          mns[7]   = "August";
          mns[8]   = "September";
          mns[9]   = "October";
          mns[10]  = "November";
          mns[11]  = "December";
           
        if(second<10)
            {
                second = "0"+second;
            }
            
        if(minute<10)
            {
                minute = "0"+minute;
            }
            
        if(hour24<=12)
            {
                ampm = "AM";
            }
            
        else
            {
                ampm = "PM"
            }
            
        if(hour24>=12)
            {
                hour= hour-12;
            }
            
        if(hour24==0)
            {
                hour=12;
            }
        
             document.getElementById('live_clock').innerHTML=(hour+":"+minute+":"+second+" "+ampm+'<br>'+days[day]+', '+date+' '+mns[month]+' '+year);
             setInterval('live_clock()', 1000);
    }
            window.onload = live_clock;
Thats the JS script ^ in my html page i have:

Code:
<div align=center>
<div id="live_clock" align="center" class=clock style="background-color: #ffffff;max-width:150px;">
</div>
Hope you can help me out!

Last edited by thefollower : 10-15-2008 at 07:35 PM.
thefollower is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-17-2008, 03:37 PM Re: Firefox freezes and stops responding IE doesnt
logic ali's Avatar
Skilled Talker

Posts: 86
Quote:
Originally Posted by thefollower View Post
Code:
setInterval('live_clock()', 1000);
You can't call setInterval repeatedly. Either use setTimeout in its place or remove the call and initialise the code like this:
Code:
window.onload=function(){setInterval(live_clock, 1000);}
__________________
556E677261746566756C204261737461726473
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Firefox freezes and stops responding IE doesnt
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11692 seconds with 12 queries