views:

72

answers:

5

I have a web site that gets a new page every couple weeks, and that means I need to update the menu to have the new page in every single one. I'm wondering if there is a way to have an external text or .htm file that I can basically insert into the web page. That way I can put the menu in the external file and call it wherever I want it. So I only have to edit one thing when I get a new page.

Thanks in advance.

Edit: This is a drop-down menu with ul and li tags with an external style sheet for them. So this needs to work for that too. Thanks

A: 

This is very easy and common to do on sites that use a server-side language behind them (PHP, ASP.NET, etc.)

If you don't want to use a server side language, than an <iframe> is your only option.

Stargazer712
Or an ordinary frameset... </dirtytalk>
Jaymz
A: 

If you want to use HTML, and only html (no server side programming or javascript), you can use Server Side Includes embedded into your html files. Your web server may need to be configured to accept them.

GrandmasterB
Any idea how I configure it?
Doug
You mean set up SSI on an apache server? I'm sure if you google for it there are a gazillion (technical term) tutorials for this online.That being said, I actually like the PHP option above better, if you have access to it. Based on your original question I provided a HTML-only option.
GrandmasterB
I did Google it and it says to put some commands into a specific file which didn't work for me, and it used technical terms that had meanings I couldn't guess, (unlike your technical terms). So I had no idea what I was doing. Unfortunately I can't get the php to work with a drop down menu. So, will this work with that?
Doug
GrandmasterB
I copied the working menu into the external file, so I know it works as long as I can get the style sheet to apply to the inserted HTML code.
Doug
A: 

If you are using server side include and you had navigation in a separated file, yes you can just edit things separate.

PerlDev
A: 

You can also do this using jQuery.

$('#elementid').load('page.html');

http://api.jquery.com/load/

But this will not be SEO friendly. Also if someone has scripts turned off in their browser, then this will not work.

Tim B James
A: 

Have a single HTML page like so:

<html>
<head></head>
<body>
HTML OF LINKS HERE
</body>
</html>

Then save it as my_links.html and into the page you want to insert it... do the following. Copy and paste the whole page and it as FILENAME.PHP and then use this code:

<?php include("my_links.html"); ?>

Congratulations, you have just used PHP! Learn more about the including pages here.

Dan
You probably don't want to have the html, head, and body tags, but just the html code for the links. Include will include everything so if you looked at the resulting page it would have another set of html, head, and body tags wherever you called the include from.
Alex Zylman
The include command worked, however this is a drop down menu using <ul> and <li> tags, with an external style sheet to make it work and look good. Unfortunately this gets the menu, but is not compatible with the style sheet. Do I need to link it in the file with the menu? If so, do I need to put <head> tags around that link or just put it with the menu, or can I not use the Style Sheet at all?
Doug
You can set it up in a .htaccess or httpd.config so that .html files are parsed by PHP, if you dont want the file to have a .php extension for some reason.
GrandmasterB
I don't really know what I'm talking about, but if I had to guess, its not the .php extension thats screwing up the style sheet. I left the original menu in and it worked fine with the .php extension, I just neeed to find a way to insert it with php and still get the style sheet to work.
Doug
OK, finally got it. In the style sheet it required a <div> tag called "menu" which I had completely forgotten about. I put that tag in the external .htm file and it worked. Guess you were right Grandmaster, it was an HTML problem.Hehe, i'm an idiot.
Doug
Your welcome. :)
Dan