How can I append header and footer text through javascript calls

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

    How can I append header and footer text through javascript calls

    What I would like to do is create header and footer information for my
    webpages which are created by calling from a referenced .js page . . . for
    example
    in Header.js:
    <script language="JavaS cript">
    function CreateHeader
    {
    document.writel n("<table>")
    document.writel n("<tr>")
    document.writel n("<td>")
    document.writel n("Stuff")
    document.writel n("</td>")
    document.writel n("</tr>")
    document.writel n("</table>")

    }
    </script>

    in Index.htm:
    <body>
    <script type="text/javascript">
    onLoad="CreateH eader()"
    </script>
    </body>

    Which would give me in this case a Stuff in a one celled table.


  • Dom Leonard

    #2
    Re: How can I append header and footer text through javascript calls

    Patrick Gibbons wrote:[color=blue]
    > What I would like to do is create header and footer information for my
    > webpages which are created by calling from a referenced .js page . . . for
    > example
    > in Header.js:
    > <script language="JavaS cript">
    > function CreateHeader
    > {
    > document.writel n("<table>")
    > document.writel n("<tr>")
    > document.writel n("<td>")
    > document.writel n("Stuff")
    > document.writel n("</td>")
    > document.writel n("</tr>")
    > document.writel n("</table>")
    >
    > }
    > </script>[/color]

    Firstly, script tags are not placed in external javascript files and
    will cause errors if they are. Hence remove the SCRIPT start and end
    tags from within Header.js[color=blue]
    >
    > in Index.htm:[/color]

    Include Header.js (I personally would use lower case file names) in the
    HEAD section of the page:

    <head>
    ....
    <script type="text/javascript" src="Header.js" ></script>
    ....
    </head>[color=blue]
    > <body>[/color]

    [color=blue]
    > <script type="text/javascript">
    > onLoad="CreateH eader()"[/color]

    This will not work as coded - you can't document.write after the onload
    event. Call CreateHeader directly:

    CreateHeader(); // write header here
    [color=blue]
    > </script>
    > </body>
    >[/color]

    Similarly, at the end of the document and assuming a function
    CreateFooter exists to document writes footer HTML, include

    <script type="text/javascript">
    CreateFooter(); // write footer here
    </script>[color=blue]
    >[/color]

    Cheers,
    Dom

    Comment

    Working...