468,136 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Java-Script - where to place in html-file?

Hi newsgroup users,

I have the following java-script:
</SCRIPT>
</head>
<body text='' link='' vlink='' alink='' bgcolor='FFFFFF'>
<p>
<center><TABLE cellSpacing=1 cellPadding=1 width="60%" align=center border=0>
<TBODY>
<TR vAlign=top align=left>
<TD vAlign=top align=left>
<P align=center><FONT face=Verdana><body onload="DigitalTime()"">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%" height="30"><span id="liveclock"
style="position:absolute;left:10px;top:10px;"><scr ipt language="JavaScript"><!--
function DigitalTime()
{
if(!document.layers && !document.all)
return
var DigitalClock = new Date();
var hours = DigitalClock.getHours();
var minutes = DigitalClock.getMinutes();
var seconds = DigitalClock.getSeconds();
if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;
//change font size here to your desire
digclock = "<font size='5' face='Arial' color='black'><b>" +
"<font size='1'>Aktuelle Zeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</a></b></font>";
if (document.layers)
{
document.layers.liveclock.document.write(digclock) ;
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML = digclock;
setTimeout("DigitalTime()",1000)
}
// --></script>

How do I have to involve it in a html-file to see the javascript
work?

Thank you for your help!

Kind regards
Jul 23 '05 #1
9 1839
Here you go. The problem you were having is that you had multiple
<body> tags. I just moved the onLoad="DigitalTime()" call up to the
first <body> tag and did away with the redundant one. Hope this helps.
Please let me know if I can help in any other way. Also be careful of
word wrap in your news viewer.
<html>
<head>
<title>Clock Page</title>
</head>
<body text='' link='' vlink='' alink='' bgcolor='FFFFFF'
onload="DigitalTime()">
<p>
<center><TABLE cellSpacing="1" cellPadding="1" width="60%"
align="center" border="0" ID="Table1">
<TBODY>
<TR vAlign="top" align="left">
<TD vAlign="top" align="left">
<P align="center"><FONT face="Verdana">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="100%"
ID="Table2">
<tr>
<td width="100%" height="30"><span id="liveclock"
style="position:absolute;left:10px;top:10px;"><scr ipt
language="JavaScript"><!--
function DigitalTime()
{
if(!document.layers && !document.all)
return
var DigitalClock = new Date();
var hours = DigitalClock.getHours();
var minutes = DigitalClock.getMinutes();
var seconds = DigitalClock.getSeconds();
if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;
//change font size here to your desire
digclock = "<font size='5' face='Arial' color='black'><b>" +
"<font size='1'>Aktuelle Zeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</a></b></font>";
if (document.layers)
{
document.layers.liveclock.document.write(digclock) ;
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML = digclock;
setTimeout("DigitalTime()",1000)
}
// --></script>
</body>
</html>






On 25 Jun 2004 02:17:06 -0700, AL****@web.de (ALuPin) wrote:
Hi newsgroup users,

I have the following java-script:
</SCRIPT>
</head>
<body text='' link='' vlink='' alink='' bgcolor='FFFFFF'>
<p>
<center><TABLE cellSpacing=1 cellPadding=1 width="60%" align=center border=0>
<TBODY>
<TR vAlign=top align=left>
<TD vAlign=top align=left>
<P align=center><FONT face=Verdana><body onload="DigitalTime()"">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%" height="30"><span id="liveclock"
style="position:absolute;left:10px;top:10px;"><scr ipt language="JavaScript"><!--
function DigitalTime()
{
if(!document.layers && !document.all)
return
var DigitalClock = new Date();
var hours = DigitalClock.getHours();
var minutes = DigitalClock.getMinutes();
var seconds = DigitalClock.getSeconds();
if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;
//change font size here to your desire
digclock = "<font size='5' face='Arial' color='black'><b>" +
"<font size='1'>Aktuelle Zeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</a></b></font>";
if (document.layers)
{
document.layers.liveclock.document.write(digclock );
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML = digclock;
setTimeout("DigitalTime()",1000)
}
// --></script>

How do I have to involve it in a html-file to see the javascript
work?

Thank you for your help!

Kind regards


Josh Austin
System Administrator
Agent Services of America
ksadmin NOSPAM @comcast.net
(remove NOSPAM and the spaces out of my email address to send email)
Jul 23 '05 #2
KsAdmin <ksadmin NO****@comcast.net> wrote in message news:<t3********************************@4ax.com>. ..
Here you go. The problem you were having is that you had multiple
<body> tags. I just moved the onLoad="DigitalTime()" call up to the
first <body> tag and did away with the redundant one. Hope this helps.
Please let me know if I can help in any other way. Also be careful of
word wrap in your news viewer.


Hi,

thank you for your help.

When I regard the html-code stand-alone in a browser
it is ok now.

I have some html-code created by Dreamweaver. When I insert the
clock-html-code I cannot see the clock.
Where might be a conflict?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
margin-right: 0px;
}
..Stil1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW ||
innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->

</head>
<body text='' link='' vlink='' alink='' bgcolor='000000'
onload="DigitalTime()">
<p>
<center><TABLE cellSpacing="1" cellPadding="1" width="60%"
align="center" border="0" ID="Table1">
<TBODY>
<TR vAlign="top" align="left">
<TD vAlign="top" align="left">
<P align="center"><FONT face="Verdana">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="100%"
ID="Table2">
<tr>
<td width="100%" height="30"><span id="liveclock"
style="position:absolute;left:10px;top:10px;">
<script
language="JavaScript"><!--
function DigitalTime()
{
if(!document.layers && !document.all)
return
var DigitalClock = new Date();
var hours = DigitalClock.getHours();
var minutes = DigitalClock.getMinutes();
var seconds = DigitalClock.getSeconds();
if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;
//change font size here to your desire
digclock = "<font size='4' face='Arial' color='white'><b>" +
"<font size='1'>Uhrzeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</a></b></font>";
if (document.layers)
{
document.layers.liveclock.document.write(digclock) ;
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML = digclock;
setTimeout("DigitalTime()",1000)
}
// --></script>
<div id="Layer1" style="position:absolute; width:200px; height:9px;
z-index:1; left: 319px; top: 75px;"><img
src="Grafiken/Willkommenseite/oben_01.gif" width="500"
height="3"></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="Layer2" style="position:absolute; width:1px; height:115px;
z-index:2; left: 816px; top: 127px;"><img
src="Grafiken/Willkommenseite/rechts_01.gif" width="3"
height="400"></div>
<div id="Layer3" style="position:absolute; width:200px; height:0px;
z-index:3; left: 119px; top: 527px;"><img
src="Grafiken/Willkommenseite/unten_01.gif" width="700"
height="3"></div>
<div id="Layer4" style="position:absolute; width:2px; height:115px;
z-index:4; left: 119px; top: 188px;"><img
src="Grafiken/Willkommenseite/links_01.gif" width="3"
height="340"></div>
<div id="Layer5" style="position:absolute; width:340px; height:13px;
z-index:5; font-family: Arial, Helvetica, sans-serif; font-size: 16px;
left: 482px; top: 51px; font-weight: bold;">Herzlich Willkommen auf
meiner Homepage </div>
<div id="Layer6" style="position:absolute; width:132px; height:115px;
z-index:10; left: 338px; top: 367px;"><a href="vhdl_start.htm"
target="_self"><img src="Grafiken/Willkommenseite/byte_feld_fpga_kurve.gif"
width="129" height="154" border="0"></a></div>
<div id="Layer9" style="position:absolute; width:211px; height:18px;
z-index:9; left: 614px; top: 541px;"><span
class="Stil1">&nbsp;<strong>em***@andres-vazquez.de</strong></span></div>
<div id="Layer7" style="position:absolute; width:200px; height:47px;
z-index:11; left: 186px; top: 534px;"><img
src="Grafiken/Willkommenseite/linpipi.gif" width="378"
height="54"></div>
<div id="Layer8" style="position:absolute; width:43px; height:33px;
z-index:12; left: 564px; top: 530px;"><a
href="mailto:em***@andres-vazquez.de"><img
src="Grafiken/Willkommenseite/mail.gif" width="50" height="42"
border="0"></a></div>
<div id="Layer10" style="position:absolute; width:111px; height:80px;
z-index:13; left: 477px; top: 367px;"><img
src="Grafiken/Willkommenseite/fotos.gif" width="129"
height="154"></div>
</body>
</html>
Jul 23 '05 #3
Lee
ALuPin said:

KsAdmin <ksadmin NO****@comcast.net> wrote in message
news:<t3********************************@4ax.com> ...
Here you go. The problem you were having is that you had multiple
<body> tags. I just moved the onLoad="DigitalTime()" call up to the
first <body> tag and did away with the redundant one. Hope this helps.
Please let me know if I can help in any other way. Also be careful of
word wrap in your news viewer.


Hi,

thank you for your help.

When I regard the html-code stand-alone in a browser
it is ok now.

I have some html-code created by Dreamweaver. When I insert the
clock-html-code I cannot see the clock.
Where might be a conflict?


1. The clock code that you found might have been good
five years ago, but it is badly obsolete. It will
not work at all in some modern browsers.

2. The script needs to be moved outside of the <span>
tag that currently contains it. Put it in the
<head> section. The way this clock updates the
display is by replacing the contents of that <span>
with the current time. That erases the script.

Jul 23 '05 #4
Hi,

thank you for your answer. I have tried the following, but still
no clock to see.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
margin-right: 0px;
}
..Stil1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW ||
innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function DigitalTime()
{
if(!document.layers && !document.all)
return
var DigitalClock = new Date();
var hours = DigitalClock.getHours();
var minutes = DigitalClock.getMinutes();
var seconds = DigitalClock.getSeconds();
if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;
//change font size here to your desire
digclock = "<font size='4' face='Arial' color='white'><b>" +
"<font size='1'>Uhrzeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</a></b></font>";
if (document.layers)
{
document.layers.liveclock.document.write(digclock) ;
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML = digclock;
setTimeout("DigitalTime()",1000)
}
//-->
</script>

</head>
<body onload="DigitalTime()">

<div id="Layer1" style="position:absolute; width:200px; height:9px;
z-index:1; left: 319px; top: 75px;"><img
src="Grafiken/Willkommenseite/oben_01.gif" width="500"
height="3"></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="Layer2" style="position:absolute; width:1px; height:115px;
z-index:2; left: 816px; top: 127px;"><img
src="Grafiken/Willkommenseite/rechts_01.gif" width="3"
height="400"></div>
<div id="Layer3" style="position:absolute; width:200px; height:0px;
z-index:3; left: 119px; top: 527px;"><img
src="Grafiken/Willkommenseite/unten_01.gif" width="700"
height="3"></div>
<div id="Layer4" style="position:absolute; width:2px; height:115px;
z-index:4; left: 119px; top: 188px;"><img
src="Grafiken/Willkommenseite/links_01.gif" width="3"
height="340"></div>
<div id="Layer5" style="position:absolute; width:340px; height:13px;
z-index:5; font-family: Arial, Helvetica, sans-serif; font-size: 16px;
left: 482px; top: 51px; font-weight: bold;">Herzlich Willkommen auf
meiner Homepage </div>
<div id="Layer6" style="position:absolute; width:132px; height:115px;
z-index:10; left: 338px; top: 367px;"><img
src="Grafiken/Willkommenseite/byte_feld_fpga_kurve.gif" width="129"
height="154" border="0" usemap="#Map2">
<map name="Map2">
<area shape="rect" coords="28,44,99,112" href="vhdl_start.htm">
</map>
</div>
<div id="Layer9" style="position:absolute; width:211px; height:18px;
z-index:9; left: 614px; top: 541px;"><span
class="Stil1">&nbsp;<strong>em***@andres-vazquez.de</strong></span></div>
<div id="Layer8" style="position:absolute; width:43px; height:33px;
z-index:12; left: 564px; top: 530px;"><a
href="mailto:em***@andres-vazquez.de"><img
src="Grafiken/Willkommenseite/mail.gif" width="50" height="42"
border="0"></a></div>
<div id="Layer10" style="position:absolute; width:111px; height:57px;
z-index:13; left: 477px; top: 367px;"><img
src="Grafiken/Willkommenseite/fotos.gif" width="129" height="154"
border="0" usemap="#Map">
<map name="Map">
<area shape="poly"
coords="33,105,47,105,55,114,86,107,110,102,108,82 ,97,69,60,76,57,47,42,42,28,42,24,50,28,97"
href="fotogallerien.htm" target="_self">
</map>
</div>
<div id="Layer7" style="position:absolute; width:358px; height:34px;
z-index:14; left: 186px; top: 541px;"><img
src="Grafiken/Willkommenseite/linpipi.gif" width="378"
height="54"></div>
</body>
</html>
Jul 23 '05 #5
Lee
ALuPin said:

Hi,

thank you for your answer. I have tried the following, but still
no clock to see.


You've also taken out the span that had the id "liveclock".
That span must exist, but it can be empty, now that the
code has moved to the head.

Jul 23 '05 #6
Lee <RE**************@cox.net> wrote in message news:<cb*********@drn.newsguy.com>...
ALuPin said:
Hi,

thank you for your help.

When I regard the html-code stand-alone in a browser
it is ok now.

I have some html-code created by Dreamweaver. When I insert the
clock-html-code I cannot see the clock.
Where might be a conflict?


1. The clock code that you found might have been good
five years ago, but it is badly obsolete. It will
not work at all in some modern browsers.

2. The script needs to be moved outside of the <span>
tag that currently contains it. Put it in the
<head> section. The way this clock updates the
display is by replacing the contents of that <span>
with the current time. That erases the script.


I modified the script.

Some changes:
- moved the function to the head area. This is the normal location
for functions to be placed. Netscape 4.x on MacOS couldn't find the
function as it was coded.
- declared all variables
- consistant casing and naming of variables
- formated the javascript code
- fixed some problems with the html. Why the absolute positioning &
nested tables? This seems redundant.
- got it to work with modern browsers like Netscape 7.1

Tested with Netscape 7.1, IE 5.2, and Netscape 4.77 on MacOS X. The
position of the time script was diferent on Netscape and IE.

When posting code, try to make it reading of the code as easy as
possible. Format it to be readable. Make you HTML code as error free
as possible.

Here is the revised code:

<html>
<head>
<title>Clock Page</title>

<script language="JavaScript">
function digitalTime()
{

var digitalClock = new Date();
var hours = digitalClock.getHours();
var minutes = digitalClock.getMinutes();
var seconds = digitalClock.getSeconds();

if (minutes <= 9)
minutes = "0" + minutes;
if (seconds <= 9)
seconds = "0" + seconds;

//change font size here to your desire
var formatClock = "<font size='5' face='Arial' color='black'><b>" +
"<font size='1'>Aktuelle Zeit:</font></br>" +
hours + ":" + minutes + ":" + seconds + "</b></font>";

if (document.getElementById)
{
document.getElementById('liveclock').innerHTML = formatClock;
}
else if (document.layers)
{
document.layers.liveclock.document.write(formatClo ck);
document.layers.liveclock.document.close();
}
else if (document.all)
{
liveclock.innerHTML = formatClock;
}
else
{;}

setTimeout("digitalTime()",1000)
}
</script>
</head>
<body text='' link='' vlink='' alink='' bgcolor='FFFFFF'
onload="digitalTime()">
<p>
<center>
<TABLE cellSpacing="1" cellPadding="1" width="60%"
align="center" border="0" ID="Table1">
<TBODY>
<TR vAlign="top" align="left">
<TD vAlign="top" align="left">
<P align="center"><FONT face="Verdana">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="100%"
ID="Table2">
<tr>
<td width="100%" height="30">
<span id="liveclock"
style="position:absolute;left:10px;top:10px;">
</table>
</div>
</table>
</body>
</html>
Jul 23 '05 #7
Thank you.
It works now :O)

One more question about that issue:

The clock that is involved in the script is the PC clock.

Is there a simple possibility to involve an always correct clock
i.e. an atomic clock placed somewhere in the internet?

Rgds
Jul 23 '05 #8
On Thu, 01 Jul 2004 08:03:13 -0700, ALuPin wrote:
Thank you.
It works now :O)

One more question about that issue:

The clock that is involved in the script is the PC clock.

Is there a simple possibility to involve an always correct clock i.e. an
atomic clock placed somewhere in the internet?

Rgds


ntpd (Network Time Protocol Daemon)
or
Window Time Service

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #9
AL****@web.de (ALuPin) wrote in message news:<b8**************************@posting.google. com>...
Thank you.
It works now :O)

One more question about that issue:

The clock that is involved in the script is the PC clock.

Is there a simple possibility to involve an always correct clock
i.e. an atomic clock placed somewhere in the internet?

Rgds


Why display the clock anyway? It is already on the screen of most all
GUIs.

The algorithm may miss a second every once in awhile. The code always
skip a second. The code takes time to run. The exact millisecond the
code starts drifts over time. You need to adjust the milliseconds so
they are near the start of the next second.

Robert
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Rokamp | last post: by
2 posts views Thread by Patrick | last post: by
1 post views Thread by ptaz | last post: by
reply views Thread by fabio | last post: by
5 posts views Thread by Thomas G. Marshall | last post: by
5 posts views Thread by TZESENG | last post: by
2 posts views Thread by Tim Murray | last post: by
oll3i
reply views Thread by oll3i | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.