By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

How can I append header and footer text through javascript calls

P: n/a
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="JavaScript">
function CreateHeader
{
document.writeln("<table>")
document.writeln("<tr>")
document.writeln("<td>")
document.writeln("Stuff")
document.writeln("</td>")
document.writeln("</tr>")
document.writeln("</table>")

}
</script>

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

Which would give me in this case a Stuff in a one celled table.
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Patrick Gibbons wrote:
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="JavaScript">
function CreateHeader
{
document.writeln("<table>")
document.writeln("<tr>")
document.writeln("<td>")
document.writeln("Stuff")
document.writeln("</td>")
document.writeln("</tr>")
document.writeln("</table>")

}
</script>
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
in Index.htm:
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> <body>
<script type="text/javascript">
onLoad="CreateHeader()"
This will not work as coded - you can't document.write after the onload
event. Call CreateHeader directly:

CreateHeader(); // write header here
</script>
</body>

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>


Cheers,
Dom

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.