Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / Javascripts / Productivaty

Source Include

Published by: Alexander Mclean III


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.


Next Javascripts Page:
1  2  [3]  4  5  6  7  8  9  10  11  12 





Hosting by iPowerWeb.com - 50 Gb for $7.95