Introduction:
With Javascript, you can save time and money by using the
("src") to include remote or local documents.
For example, you may have a web site serving 20 web pages.
All 20 pages display the same header and footer item like
site name, logos and links. However, if you were to change
the header text, you would have to apply those changes all
20 pages manualy. That's not fun. Here is a faster way (View
the test page.)
Source Code of included header file (JS-IncludeB.js):
<!--
document.writeln('<center>');
document.writeln('<h2>Top: This was included by js</h2>');
document.writeln('</center>');
// -->
Source Code of included footer file
(JS-IncludeB.js):
<!--
document.writeln('<center>');
document.writeln('<h2>Top: This was included by js</h2>');
document.writeln('</center>');
// -->
Source Code of main page:
<table width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" height="42" valign="top"
bgcolor="#66CCFF">
<script language="JavaScript" src="JS-IncludeT.js">
</script>
</td>
</tr>
<tr>
<td valign="top" height="49" bgcolor="#FFFFFF">
<script language="JavaScript" src="JS-IncludeB.js">
</script>
</td>
</tr>
<tr>
<td height="175">
</td>
</tr>
</table>
Over View:
First we created two javascript files. Inside of both
files we used the javascript's "document.writein()"
function to display our html header and footer text.
Secondly we created the main html document that used javascript's
"src" function to include our header and footer
files. Now if we had to change our header copy, all we would
have to do is edit one document, not 20 plus files. Sweeeeet!
Conclusion:
This technique can be applied to all types of situations.
For example, instead of creating two websites (a flash site and an html
site) we could just create one site
using javascript function "src" to include a flash file if a flash
plug-in is detected, otherwise it would just include the image file in place of the flash file. This would shorten
the time it takes to develop and maintain a web site. The
possibilities are endless.
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.