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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ALuPin

    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><TABL E cellSpacing=1 cellPadding=1 width="60%" align=center border=0>
    <TBODY>
    <TR vAlign=top align=left>
    <TD vAlign=top align=left>
    <P align=center><F ONT face=Verdana><b ody onload="Digital Time()"">
    <div align="left">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
    <td width="100%" height="30"><sp an id="liveclock"
    style="position :absolute;left: 10px;top:10px;" ><script language="JavaS cript"><!--
    function DigitalTime()
    {
    if(!document.la yers && !document.all)
    return
    var DigitalClock = new Date();
    var hours = DigitalClock.ge tHours();
    var minutes = DigitalClock.ge tMinutes();
    var seconds = DigitalClock.ge tSeconds();
    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'>Aktuel le Zeit:</font></br>" +
    hours + ":" + minutes + ":" + seconds + "</a></b></font>";
    if (document.layer s)
    {
    document.layers .liveclock.docu ment.write(digc lock);
    document.layers .liveclock.docu ment.close();
    }
    else if (document.all)
    liveclock.inner HTML = digclock;
    setTimeout("Dig italTime()",100 0)
    }
    // --></script>

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

    Thank you for your help!

    Kind regards
  • KsAdmin

    #2
    Re: Java-Script - where to place in html-file?

    Here you go. The problem you were having is that you had multiple
    <body> tags. I just moved the onLoad="Digital Time()" 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="Digital Time()">
    <p>
    <center><TABL E 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"><sp an id="liveclock"
    style="position :absolute;left: 10px;top:10px;" ><script
    language="JavaS cript"><!--
    function DigitalTime()
    {
    if(!document.la yers && !document.all)
    return
    var DigitalClock = new Date();
    var hours = DigitalClock.ge tHours();
    var minutes = DigitalClock.ge tMinutes();
    var seconds = DigitalClock.ge tSeconds();
    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'>Aktuel le Zeit:</font></br>" +
    hours + ":" + minutes + ":" + seconds + "</a></b></font>";
    if (document.layer s)
    {
    document.layers .liveclock.docu ment.write(digc lock);
    document.layers .liveclock.docu ment.close();
    }
    else if (document.all)
    liveclock.inner HTML = digclock;
    setTimeout("Dig italTime()",100 0)
    }
    // --></script>
    </body>
    </html>
















    On 25 Jun 2004 02:17:06 -0700, ALuPin@web.de (ALuPin) wrote:
    [color=blue]
    >Hi newsgroup users,
    >
    >I have the following java-script:
    >
    >
    ></SCRIPT>
    ></head>
    > <body text='' link='' vlink='' alink='' bgcolor='FFFFFF '>
    ><p>
    ><center><TAB LE cellSpacing=1 cellPadding=1 width="60%" align=center border=0>
    ><TBODY>
    ><TR vAlign=top align=left>
    ><TD vAlign=top align=left>
    ><P align=center><F ONT face=Verdana><b ody onload="Digital Time()"">
    ><div align="left">
    ><table border="0" cellpadding="0" cellspacing="0" width="100%">
    > <tr>
    > <td width="100%" height="30"><sp an id="liveclock"
    > style="position :absolute;left: 10px;top:10px;" ><script language="JavaS cript"><!--
    >function DigitalTime()
    >{
    >if(!document.l ayers && !document.all)
    >return
    >var DigitalClock = new Date();
    >var hours = DigitalClock.ge tHours();
    >var minutes = DigitalClock.ge tMinutes();
    >var seconds = DigitalClock.ge tSeconds();
    >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'>Aktuel le Zeit:</font></br>" +
    >hours + ":" + minutes + ":" + seconds + "</a></b></font>";
    >if (document.layer s)
    >{
    >document.layer s.liveclock.doc ument.write(dig clock);
    >document.layer s.liveclock.doc ument.close();
    >}
    >else if (document.all)
    >liveclock.inne rHTML = digclock;
    >setTimeout("Di gitalTime()",10 00)
    >}
    >// --></script>
    >
    >How do I have to involve it in a html-file to see the javascript
    >work?
    >
    >Thank you for your help!
    >
    >Kind regards[/color]

    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)

    Comment

    • ALuPin

      #3
      Re: Java-Script - where to place in html-file?

      KsAdmin <ksadmin NOSPAM@comcast. net> wrote in message news:<t3hod0t99 re9ahc3mg3msf4s mh6tajh26a@4ax. com>...[color=blue]
      > Here you go. The problem you were having is that you had multiple
      > <body> tags. I just moved the onLoad="Digital Time()" 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.[/color]



      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>Unbenann tes 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="JavaS cript" type="text/JavaScript">
      <!--
      function MM_reloadPage(i nit) { //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if
      ((appName=="Net scape")&&(parse Int(appVersion) ==4)) {
      document.MM_pgW =innerWidth; document.MM_pgH =innerHeight;
      onresize=MM_rel oadPage; }}
      else if (innerWidth!=do cument.MM_pgW ||
      innerHeight!=do cument.MM_pgH) location.reload ();
      }
      MM_reloadPage(t rue);
      //-->

      </head>
      <body text='' link='' vlink='' alink='' bgcolor='000000 '
      onload="Digital Time()">
      <p>
      <center><TABL E 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"><sp an id="liveclock"
      style="position :absolute;left: 10px;top:10px;" >
      <script
      language="JavaS cript"><!--
      function DigitalTime()
      {
      if(!document.la yers && !document.all)
      return
      var DigitalClock = new Date();
      var hours = DigitalClock.ge tHours();
      var minutes = DigitalClock.ge tMinutes();
      var seconds = DigitalClock.ge tSeconds();
      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'>Uhrzei t:</font></br>" +
      hours + ":" + minutes + ":" + seconds + "</a></b></font>";
      if (document.layer s)
      {
      document.layers .liveclock.docu ment.write(digc lock);
      document.layers .liveclock.docu ment.close();
      }
      else if (document.all)
      liveclock.inner HTML = digclock;
      setTimeout("Dig italTime()",100 0)
      }
      // --></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_star t.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 ail@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 ail@andres-vazquez.de"><im g
      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>

      Comment

      • Lee

        #4
        Re: Java-Script - where to place in html-file?

        ALuPin said:[color=blue]
        >
        >KsAdmin <ksadmin NOSPAM@comcast. net> wrote in message
        >news:<t3hod0t9 9re9ahc3mg3msf4 smh6tajh26a@4ax .com>...[color=green]
        >> Here you go. The problem you were having is that you had multiple
        >> <body> tags. I just moved the onLoad="Digital Time()" 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.[/color]
        >
        >
        >
        >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?[/color]

        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.

        Comment

        • ALuPin

          #5
          Re: Java-Script - where to place in html-file?

          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>Unbenann tes 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="JavaS cript" type="text/JavaScript">
          <!--
          function MM_reloadPage(i nit) { //reloads the window if Nav4 resized
          if (init==true) with (navigator) {if
          ((appName=="Net scape")&&(parse Int(appVersion) ==4)) {
          document.MM_pgW =innerWidth; document.MM_pgH =innerHeight;
          onresize=MM_rel oadPage; }}
          else if (innerWidth!=do cument.MM_pgW ||
          innerHeight!=do cument.MM_pgH) location.reload ();
          }
          MM_reloadPage(t rue);
          //-->
          </script>
          <script language="JavaS cript" type="text/JavaScript">
          <!--
          function DigitalTime()
          {
          if(!document.la yers && !document.all)
          return
          var DigitalClock = new Date();
          var hours = DigitalClock.ge tHours();
          var minutes = DigitalClock.ge tMinutes();
          var seconds = DigitalClock.ge tSeconds();
          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'>Uhrzei t:</font></br>" +
          hours + ":" + minutes + ":" + seconds + "</a></b></font>";
          if (document.layer s)
          {
          document.layers .liveclock.docu ment.write(digc lock);
          document.layers .liveclock.docu ment.close();
          }
          else if (document.all)
          liveclock.inner HTML = digclock;
          setTimeout("Dig italTime()",100 0)
          }
          //-->
          </script>

          </head>
          <body onload="Digital Time()">

          <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,9 9,112" href="vhdl_star t.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 ail@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 ail@andres-vazquez.de"><im g
          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,8 6,107,110,102,1 08,82,97,69,60, 76,57,47,42,42, 28,42,24,50,28, 97"
          href="fotogalle rien.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>

          Comment

          • Lee

            #6
            Re: Java-Script - where to place in html-file?

            ALuPin said:[color=blue]
            >
            >Hi,
            >
            >thank you for your answer. I have tried the following, but still
            >no clock to see.[/color]

            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.

            Comment

            • Robert

              #7
              Re: Java-Script - where to place in html-file?

              Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<cbru8r02j c0@drn.newsguy. com>...[color=blue]
              > ALuPin said:[color=green]
              > >[/color][/color]
              [color=blue][color=green]
              > >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?[/color]
              >
              > 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.[/color]

              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="JavaS cript">
              function digitalTime()
              {

              var digitalClock = new Date();
              var hours = digitalClock.ge tHours();
              var minutes = digitalClock.ge tMinutes();
              var seconds = digitalClock.ge tSeconds();

              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'>Aktuel le Zeit:</font></br>" +
              hours + ":" + minutes + ":" + seconds + "</b></font>";

              if (document.getEl ementById)
              {
              document.getEle mentById('livec lock').innerHTM L = formatClock;
              }
              else if (document.layer s)
              {
              document.layers .liveclock.docu ment.write(form atClock);
              document.layers .liveclock.docu ment.close();
              }
              else if (document.all)
              {
              liveclock.inner HTML = formatClock;
              }
              else
              {;}

              setTimeout("dig italTime()",100 0)
              }
              </script>
              </head>
              <body text='' link='' vlink='' alink='' bgcolor='FFFFFF '
              onload="digital Time()">
              <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>

              Comment

              • ALuPin

                #8
                Re: Java-Script - where to place in html-file?

                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

                Comment

                • Ivan Marsh

                  #9
                  Re: Java-Script - where to place in html-file?

                  On Thu, 01 Jul 2004 08:03:13 -0700, ALuPin wrote:
                  [color=blue]
                  > 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[/color]

                  ntpd (Network Time Protocol Daemon)
                  or
                  Window Time Service

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

                  Comment

                  • Robert

                    #10
                    Re: Java-Script - where to place in html-file?

                    ALuPin@web.de (ALuPin) wrote in message news:<b8a9a7b0. 0407010703.7c4d e10d@posting.go ogle.com>...[color=blue]
                    > 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[/color]

                    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

                    Comment

                    Working...