I've created a little dropdown menu with javascript. And I want this on each page of my website. I thought about adding it via iframe but it extends downwards and put a scroll bar in the iframe.

I don't want to copy/paste the dropdown menu to each page because I'll probably change it later, what do you suggest doing.

Recommended Answers

All 7 Replies

Server side include.

Put the code for the menu in a separate file and include it in each page. When you update that one include file, it will update all pages that have the file included, without having to go update each page manually.

<!--#include file="included.html" -->
<!--#include virtual="/directory/included.html" -->

Learn more at:


Ok so this can go in the body correct?

Darn, the server I'm submitting to(old school server) doesn't support these. Is there any way I can do this with JavaScript?

if your script is purely javascript, you can put that script in a .js file (myMenu.js).

Then, include that file where you want the menu like:

<script src="myMenu.js" type="text/javascript"></script>

Just be sure you have the correct path to the src (source) file listed and it should include that .js file in whatever page you want. Then if you want changes, just update your .js file and all the pages change.

No a lot me it is in tables and lists. They just extend using JavaScript. I heard something about interHTML. But how would I load in a file using it.

then create a javascript function that builds up the menu, then include the script in ever page and the function will create everywhere the same menu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.