Michele Basso
a- a+

Visualizzare un calendario e un orologio

Con questo script, possiamo inserire un orologio e uncalendario all'interno di una pagina web.

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

<script language="JavaScript"><!--var mese; var anno; function fill_table(m,month_length,y,m1){   var myc = ""  var myc1  day = 1  //**********************************************************************//// per variare i colori del calendario agire sulle seguenti variabili     var c1 = "Blue"// colore del nome dei giorni della settimana;   var c2 = "Red" // colore del nome del giorno "dom";  var c4 = "#993300"   // colore dell'intestazione (nome mese e anno);  var c5 = "#009900"   // colore del giorno corrente;//**********************************************************************//    var data_oggi = new Date()  var gg_oggi = data_oggi.getDate()  var mm_oggi = data_oggi.getMonth()  var aa_oggi = data_oggi.getFullYear()  var hours = data_oggi.getHours()  var minutes = data_oggi.getMinutes()  var seconds = data_oggi.getSeconds()    if (minutes <= 9)     minutes = "0" + minutes;  if (seconds <= 9)     seconds = "0" + seconds;    if (start_day == 0)     start_day = 1;    myc = myc + ("<table border=0 cellspacing=0 cellpadding=0>")  myc = myc + ("<TR><TD COLSPAN=7 ALIGN=center><font size=-1 color=" +c4+ ">" +m+ "   " +y+ " ore " +hours+ ":" +minutes+ ":" +seconds+ "</font></TR><TR>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Lun</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Mar</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Mer</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Gio</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Ven</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c1+ ">Sab</font></TD>")  myc = myc + ("<TD ALIGN=center WIDTH=28><font size=-1 color=" +c2+ ">Dom</font></TD>")  myc = myc + ("</TR><TR>")  for (var i=1;i<start_day;i++){ myc = myc + ("<td></td>")  }    for (var i=start_day;i<8;i++){   if ((day == gg_oggi) && (m1 == mm_oggi) && (y == aa_oggi)) {     myc1 = ("<TD ALIGN=center><font size=-1 color=" +c5+ ">" +day+ "</font></TD>") }    else {     myc1 = ("<TD ALIGN=center><font size=-1>" +day+ "</font></TD>")  }myc = myc + myc1 day++  }  myc = myc + ("</TR><TR>")    while (day <= month_length) {     for (var i=1;i<=7 && day<=month_length;i++){   if ((day == gg_oggi) && (m1 == mm_oggi) && (y == aa_oggi)) {   myc1 = ("<TD ALIGN=center><font size=-1 color=" +c5+ ">" +day+ "</font></TD>") } else {   myc1 = ("<TD ALIGN=center><font size=-1>" +day+ "</font></TD>")    }    myc = myc + myc1    day++     }    myc = myc + ("</TR><TR>")  }  myc = myc + ("</TR></TABLE><BR>")    if (document.layers){document.layers.bc.document.write(myc)document.layers.bc.document.close()   }  else if (document.all)bc.innerHTML=mycsetTimeout("carica_mese(0)" ,1000);  } function carica_mese(n){  if (!document.layers&&!document.all) return  var mydate = new Date() var year = mydate.getFullYear() var month = mydate.getMonth()   if (month == 0) {   today= new Date("January 1, " +year)   start_day = today.getDay()   fill_table("Gennaio" ,31,year,month) } if (month == 1) {   today= new Date("February 1, " +year)   start_day = today.getDay()   fill_table("Febbraio" ,28,year,month) }    if (month == 2) {   today= new Date("March 1, " +year)   start_day = today.getDay()   fill_table("Marzo" ,31,year,month) }  if (month == 3) {   today= new Date("April 1, " +year)   start_day = today.getDay()   fill_table("Aprile" ,30,year,month) }     if (month == 4) {   today= new Date("May 1, " +year)   start_day = today.getDay()   fill_table("Maggio" ,31,year,month) }  if (month == 5) {   today= new Date("June 1, " +year)   start_day = today.getDay()   fill_table("Giugno" ,30,year,month) }  if (month == 6) {   today= new Date("July 1, " +year)   start_day = today.getDay()   fill_table("Luglio" ,31,year,month) } if (month == 7) {   today= new Date("August 1, " +year)   start_day = today.getDay()   fill_table("Agosto" ,31,year,month) }  if (month == 8) {   today= new Date("September 1, " +year)   start_day = today.getDay()   fill_table("Settembre" ,30,year,month) }  if (month == 9) {   today= new Date("October 1, " +year)   start_day = today.getDay()   fill_table("Ottobre" ,31,year,month) }  if (month == 10) {   today= new Date("November 1, " +year)   start_day = today.getDay()   fill_table("Novembre" ,30,year,month) }  if (month == 11) {   today= new Date("December 1, " +year)   start_day = today.getDay()   fill_table("Dicembre" ,31,year,month) }   mese = month;    }//--></script>

Agendo sul codice che abbiamo inserito, possiamo anchemodificare i colori del calendario; nello specifico, facciamoriferimento a queste righe:

var c1 = "Blue" // colore del nome dei giorni della settimana; var c2 = "Red" // colore del nome del giorno "dom";var c4 = "#993300" // colore dell'intestazione (nome mese e anno);var c5 = "#009900" // colore del giorno corrente;

Adesso aggiungiamo al tag body l'attributoonLoad="carica_mese(0)"
Esempio:

<BODY onLoad="carica_mese(0)">

E adesso, inseriamo questo codice nel punto in cui vogliamoche compaiano l'orologio e il calendario:

<span id="bc" style="position: absolute;left:280;top:100;"></span><!-- Script offerto da Franco Mungari francoeassunta@iol.it --><font face="Times New Roman">

L'unica nota importante riguarda il mantenimento deiriferimenti all'autore quando si utilizza lo script.

Per problemi relativi all'utilizzo di questojavascript, potete consultare il nostroforum.