Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 1
Trades: 0
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 06:35 PM..
thefollower is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-17-2008, 02:37 PM Re: Firefox freezes and stops responding IE doesnt
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
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);}
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Firefox freezes and stops responding IE doesnt
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.15635 seconds with 12 queries