Click to See Complete Forum and Search --> : Newbie with question about running a clock in both IE and Netscape


julchek
12-05-2002, 12:15 PM
Hi -
I am trying to use this script in a site, but the clock doesn't work in netscape - is there something I am missing in this that would make the script work in Netscape?

<script language="Javascript1.2">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var tags_before_clock = "<small>"
var tags_after_clock = "</small>"

if(navigator.appName == "Netscape") {
document.write('<layer id="clock"></layer><br>');
}

if (navigator.appVersion.indexOf("MSIE") != -1){
document.write('<span id="clock"></span><br>');
}

function upclock(){
var dte = new Date();
var hrs = dte.getHours();
var min = dte.getMinutes();
var sec = dte.getSeconds();
var col = ":";
var spc = " ";
var apm;

if (12 < hrs) {
apm="PM";
hrs-=12;
}

else {
apm="AM";
}

if (hrs == 0) hrs=12;
if (min<=9) min="0"+min;
if (sec<=9) sec="0"+sec;

if(navigator.appName == "Netscape") {
document.clock.document.write(tags_before_clock
+hrs+col+min+col+sec+spc+apm+tags_after_clock);
document.clock.document.close();
}

if (navigator.appVersion.indexOf("MSIE") != -1){
clock.innerHTML = tags_before_clock+hrs
+col+min+col+sec+spc+apm+tags_after_clock;
}
}

setInterval("upclock()",1000);
//-->
</script>

Thanks - also, does anyone have ideas about where to find a script with a pulldown menu that doesn't use the arrows to indicate that it drops down, but rather just automatically pulls down the menu when you mouse over it?

gil davis
12-05-2002, 02:31 PM
Works fine on NS 4.8 and Windows '98.

julchek
12-05-2002, 07:50 PM
I am not getting anything when I run this code in Netscape 6.2 and Windows 2000 Professional. ??

But thanks for letting me know that you were able to get the time in Netscape 4.X and Windows 98

gil davis
12-06-2002, 06:55 AM
NS 6, NS 7 and Mozilla are W3C DOM compliant browsers. They do not support the "document.layers" array or the "layer" tag. If you had been specific in your first post, you would have received a better annswer from me.

Change all occurrences of this:

if(navigator.appName == "Netscape") {

to this:

if(document.layers) {

and add this at the end of the function "upclock()" (before the last "}":

if (document.getElementById && !document.all)
{document.getElementById("clock").innerHTML = tags_before_clock+hrs+col+min+col+sec+spc+apm+tags_after_clock;}

julchek
12-06-2002, 09:16 AM
Thank you, Gil. I am pretty new to this, so I didn't know totally what I was asking for. I appreciate the help, and I'll take your advice on fixing this. :D