Learn how to save time and money by using the javascript src() function to including local or remote document like headers, footers, css, images, and flash files.
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>




What if the user visiting the page hasn’t activated JavaScript in his browser, then what happens?
Thanks,
As most developer understand that Javascript is not the most reliable tool for creating dynamic website for that reason you should consider using server side programs like PHP, CGI, ASP or Java… ect.
Take a look at this PHP tutorial that talks about include functions:
http://newsourcemedia.com/index_view.php?id=56
i am using Swish to create a flash website, i can run Javascripts within the flash file that Swish creates.
what code would i use to include a .txt file?
thanks
You could use loadVariablesNum(“params.txt”, 0); or loadVariables(“params.txt”, target_mc);
Well, That’s a very good idea but I have two questions.
1) What are we supposed to do when we want to make the same thing with an image or with a flash?
2)Is there a script with which we can keep the images and other stuff and only change the text in order to save time creating an HTML page for each? (i.e. lyrics of songs). Thanks!
How can i know the implementation of content management, because your demo page is not opening.
thanking you.
The test view link is now fixed
Thank you for this tutorial. Sure it will help greatly.
Thank you. Your tutorial helped me a lot.