Tuesday, June 23, 2009

How to use header or footer in all pages of your HTML website

With Javascript Includes

A javascript include is exactly the same as using an external javascript file. However, typically, when using javascript as an include, you would be using the javascript to actually output something into the browser rather than just storing and running various functions.

If you are planning to use javascript includes for any reason, remember that the code in your javascript file has to be javascript. In other words, rather than simply using:

you will need to create that HTML using javascript, similar to:

var navmenu = document.createElement('ul'); navmenu.id = "navmenu"; for(var i=1;i<=4;i++) { var navitem = document.createElement('li'); var navlink = document.createElement('a'); navlink.href = "page"+i+".html"; navlink.appendChild(document.createTextNode("Menu Item "+i)); navitem.appendChild(navlink); } document.body.appendChild(navmenu);

Using javascript includes can be helpful in a number of ways, but should be avoided for any heavy lifting, simply because it is completely dependent on your visitors.

No comments:

Post a Comment