Re: Date Script that refreshes itself

by gdeboer(at)mediaport.org

 Date:  Wed, 19 Jan 2000 19:03:24 +0100
 To:  Sam <ssendon(at)icqmail.com>,
hwg-techniques(at)hwg.org
 In-Reply-To:  cp
  todo: View Thread, Original
At 05:11 19-1-00 -0800, Sam wrote:
>http://members.xoom.com/_XMCM/ssendon/nfsitev2/index.html
>
>Hello again,
>
>Actually, I have already sent this type of message before but did not get
any response.  I am re-writing my prev email for those who haven't read my
prev email concerning the same subject.
>
>I made a page that uses a few Javascripts including it's Date script.  I
wanted  the script to refresh everytime the minute changes so as to be
almost in synchrony with the client's system date.  To do this, i placed
the script in a floating frame and placed a meta tag to refresh the time
page every ten seconds.  The problem I am encoutering right now is the
existence of up and down arrow heads in the Floating frame when viewed in
IE5... I also tried to view it in IE4 and it shows ok without those up and
down arrow heads... but in IE5, well...
>
>anyway, my other option is to look for a script that will refresh my the
date only (every seconds, if possible) without refreshing the whole page.
Presently, I only have a rough idea.  Anyway, I hope you could give me more
options.
>
>Thanks for your replies... =)
>
>Sam

Hello Sam,

You can write the time in a textarea. With the setTimeout method it's easy.
No need to refresh the page.
With document.open()
     document.write()
     document.close()
you can write to another frame and make the clock tick also in Netscape 3.

The script below writes the time in a div:
Netscape 4 uses the syntax above. In IE4+ just use innerText or innerHTML
to change the content of a div every second:

		

<style type = "text/css">
<!--
.sec{position:absolute;visibility:hidden}
//-->
</style>
	
<script language="JavaScript">
<!--

var NN4 = document.layers ? true : false;
var IE4 = document.all ? true : false;
var dom = (NN4||IE4) ? true : false;




function writeTime() {
	if (dom) {
			
			today = new Date()
			dag = today.getDate()
			maand = today.getMonth()+1
			jaar = today.getYear()
			uur = today.getHours()
			minuut = today.getMinutes()
			if (minuut<10) {
			minuut = '0' + minuut
			}
			seconde = today.getSeconds()
			if (seconde<10) {
			seconde = '0' + seconde
			}
			

			html= 'Today is: '+dag+'-'+maand+'-'+jaar+'<br>'
			html+= 'The time: '
			html+= uur + ':' + minuut + ':' + seconde
			
						

		if (NN4) {
			
			document.layers['time'].visibility = "visible"
			lyr = document.layers['time'].document
			lyr.open()
			lyr.write(html)
			lyr.close()
						
			}
		if (IE4) {
			
			document.all['time'].style.visibility = "visible"
			document.all['time'].innerHTML = html
	
			
			}
		setTimeout('hideTime()',1000)	
	}			
}

function hideTime() {
	if (dom) {
		if (NN4) {
			document.layers['time'].visibility = "hidden"
			}
		if (IE4) {
			document.all['time'].style.visibility = "hidden"
			}
		writeTime()	
	}	
}

//-->
</script>	

In the body tag: onLoad="writeTime()"


In the document:

<DIV id="time" class="sec">
</div>


regards,

Gerard

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA