Gurpreet Singh
Gurpreet Singh

Reputation: 87

Need Menu in Separate html file

I want to create a menu which will be used in 40 to 50 pages. I want to create it in a separate file so that it can be updated easily. How to do that?

Upvotes: 3

Views: 3265

Answers (3)

Mousey
Mousey

Reputation: 1865

To put a menu (or any other HTML section) in a separate file wihout jquery or iframes you can use Server Side Includes (SSI).

  1. Create a single HTML file containing the HTML you want to include, eg the HTML of a menu that needs to be repeated in many files. Do not includ <! doctype, <head> etc. Save the file with a .shtml extension, eg menu.shtml (alough usually it works with just .html). Example:

    <ul id="navmenu">
    <li><a href="page1.shtml">Page One</a></li>
    <li><a href="page2.shtml">Page Two</a></li>
    <li><a href="page3.shtml">Page Three</a></li>
    </ul>
    
  2. Add the include statement to every file you want this menu to be put in:

     <!-- #include file="menu.shtml" -->
    

Paths are relative, using a path relative to the root of the webserver is done by:.

<!--#include virtual="/directory/menu.shtml" -->

More info

Info on SSI with php, VBScript and other languages

Upvotes: 0

schnawel007
schnawel007

Reputation: 4020

Okay there a 3 ways:

  1. PHP. Include it per PHP (include Command)
  2. JavaScript. Load it with AJAX and display it in a div. (jQuery will help you)
  3. Iframe. Dirty and ugly but it will be the fastest way

Upvotes: 0

Chris Koster
Chris Koster

Reputation: 403

Put your menu HTML somewhere and use jQuery to load it into a designated element:

$("#menu").load( "menu.html" );

Upvotes: 2

Related Questions