Source Include

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>

2 Responses

  1. Claude Gelinas

    What if the user visiting the page hasn’t activated JavaScript in his browser, then what happens?

    Thanks,

  2. Alex

    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

  3. sam

    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

  4. alex

    You could use loadVariablesNum(“params.txt”, 0); or loadVariables(“params.txt”, target_mc);

  5. xulti

    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!

  6. Ranjan

    How can i know the implementation of content management, because your demo page is not opening.

    thanking you.

  7. Alex

    The test view link is now fixed

  8. KimberlyMon

    Thank you for this tutorial. Sure it will help greatly.

  9. KimberlyMon

    Thank you. Your tutorial helped me a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »