Michele Basso
a- a+

Visualizzare un orologio

Con questo DHTML è possibile visualizzare un orologioche cambia i secondi in tempo reale, senza bisogno di farenessun refresh.

VISUALIZZA L'ESEMPIO

Per utilizzare lo script, dobbiamo inserire questo codiceall'interno del tag head:

<STYLE TYPE="text/css">   #clock {color:blue; font-size:120%} /* Format the clock. */</STYLE><SCRIPT LANGUAGE="JavaScript">   // Check whether IE4 or later.   var MS = navigator.appVersion.indexOf("MSIE");   .isIE4 = (MS > 0) &&(parseInt(navigator.appVersion.substring(MS + 5, MS + 6))    >= 4);   function lead0(val) {// Add leading 0s when necessary.return (val < 10) ? "0" + val.toString() : val;   }   function buildTime() {var time = new Date();var ampm = "AM";var h = time.getHours();// Fix military time and determine ampm.if (h > 12) {   h = h - 12;   ampm = " PM";}return lead0(h) + ":" + lead0(time.getMinutes()) + ":" +   lead0(time.getSeconds()) + ampm;   }   function tick() {// Replace the clock's time with the current time.document.all.clock.innerText = buildTime();   }</SCRIPT>

Adesso dobbiamo inserire un attributo al tag body,come nell'esempio: 

<BODY bgcolor="white" ONUNLOAD="if (null != window.tmr) clearInterval(window.tmr);" ONLOAD="if (window.isIE4) window.tmr = setInterval('tick()', 999);">

E l'orologio lo mettiamo con un codice come questo:

<SPAN ID="clock"><SCRIPT LANGUAGE="JavaScript">// Down-level script support --// output an initial static time.document.write(buildTime());</SCRIPT></SPAN>