Trying to maintain a common menu across a dozen or more html files has bugged me for a while now. I lamented the lack of a C style include statement in html. So, I finally set my programmer mind the task of solving this problem, and here it is.
1. A function to create a menu entry.
function PutMenuEntry(file, title)
if (document.title != title)
document.write("<div class=" "menu_entry" ">");
document.write("<a href=" file ">" title "</a>");
2. A function to create the full menu:
PutMenuEntry("about_us.html", "About Us");
PutMenuEntry("contact_us.html", "Contact Us");
Then, I included this in each of my html files:
Works like a champ! Now the actual menu in maintained in only one place (the script file) and the appearance is controlled in one place (the CSS style file). If I add another page, I only need to add a "PutMenuEntry" line to the "CreateMenu" function in the script file and the new button appears on the menu on all the pages.
Only thing difficult is that the title of an html file must be the same as the label on the menu button if you want it's button to not show up when that page is displayed. If you don't mind having a menu button that just reloads the current page, then it doesn't matter. Or... you could get ambitious and add another parameter to the "PutMenuEntry" function to use for disabling the button for that page.
Oh, you might be interested in the CSS that makes this look like a real menu. Here it is:
The menu itself:
#menu /* menu only appears once on any given page */
The menu entries (the buttons):
So, feel free to use any of this you find helpful. Enjoy and think of me....