Reputation: 87
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
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).
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>
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" -->
Info on SSI with php, VBScript and other languages
Upvotes: 0
Reputation: 4020
Okay there a 3 ways:
Upvotes: 0
Reputation: 403
Put your menu HTML somewhere and use jQuery to load it into a designated element:
$("#menu").load( "menu.html" );
Upvotes: 2