PDA

View Full Version : Javascript DOESN'T work on FireFox



jpe.pinho@gmail.com
07-07-2008, 04:28 PM
Hi guys, im putting this code that i found here on this website on my own to show a clock on the site. It works fine on IE but on firefox i keep getting instead of the hour, a symbol like this "NaN:NaN". Can somebody validate this script and tell me whats wrong with it? :(

i think the problem its on the first function..

var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"];

function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return;
this.container=document.getElementById(container);
this.displayversion=displayversion;
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time()) ?>' : (servermode=="server-asp")? '<%= Now() %>' : '<%= Now() %>';
this.localtime=this.serverdate=new Date(servertimestring);
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000);
this.updateTime();
this.updateContainer();
}


showLocalTime.prototype.updateTime=function(){
var thisobj=this;
this.localtime.setSeconds(this.localtime.getSeconds()+1);
setTimeout(function(){thisobj.updateTime();}, 1000);
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this;
if (this.displayversion=="long"){
this.container.innerHTML=this.localtime.toLocaleString();
}
else{
var hour=this.localtime.getHours();
var minutes=this.localtime.getMinutes();
var seconds=this.localtime.getSeconds();
var dayofweek=weekdaystxt[this.localtime.getDay()];
this.container.innerHTML=hour+":"+formatmin(minutes);
}

setTimeout(function(){thisobj.updateContainer();}, 1000);
}
function formatmin(num){
return (num<=9)? "0"+num : num;
}

function MM_findObj(n, d) {
var p,i,x;
if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
}

if(!(x=d[n])&&d.all) x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n);
return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) {
if ((obj=MM_findObj(args[i]))!=null) {
v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v;
}
}
}

allahverdi
07-07-2008, 04:32 PM
Is your js enabled? I didn't check the script...