Wednesday, August 18, 2004

Server Side includes when your server doesnot support it

This works only with HTML. A typical use will be to place some piece of html code at the top of every page on the website, used when you have a menu bar on each page. A big pain is to modify the menu, because you have to go to each and every page and do the changes to make it uniform.

Ofcourse there are other solutions like using frames so that now there is only 1 file to modify.

But what if you dont want to use frames.... Javascript to the rescue.

Use Javascript document.write method to write out the html code to your page. Place this javascript code in a something.js file and include something.js in every page where you want to have that html code present.

Including for javascript is as simple as
<script language="javascript" src="something.js">

I typically write 2 functions in this file, namely writeHeader() and writeFooter(). At the exact location where I want the code to be written I call this function

Example :
<body class="main" onload="MM_preloadImages('images/mmenuhomeon.gif','images/mmenuabouton.gif','images/mmenueventson.gif','images/mmenugovernon.gif','images/mmenubbon.gif','images/mmenulinkson.gif','images/mmenucontactoff.gif')">

<script type="text/javascript">writeHeader()script>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
...
...
-----------------------------------------------------------------




No comments: