Click to See Complete Forum and Search --> : Creating Menus using JavaScript
Mimorkeris
01-16-2005, 04:50 AM
I'm trying to find a way of being able to update the menus on each page of a site from only one source.
If you then need to add a page to a menu or sub-menu, all you need to do is edit a external file and hey presto!
I beleive this may be possible using PHP or someover script but I have no knowledge of server side scripting.
Finally I don't wish to use frames.
Does anyone have any ideas, links I could investigate.
PeOfEo
01-16-2005, 08:47 AM
Don't use javascript. If you use javascript they will fail for everyone that does not support javascript. Yes it can be done via a server side include, do you support any of the following: asp, asp.net, php, cgi, jsp, ssi, cold fucion?
Mimorkeris
01-16-2005, 02:15 PM
Thanks I hadn't thought about clients not supporting JS.
My server supports asp.
PeOfEo
01-16-2005, 02:23 PM
Okay, well just put your navigation in a .txt or .inc (a text file with a .inc extention). Then on the page that needs the menu put this code
<!--#include virtual="yourfile.txt"-->
where your file is the name of the file you are including (this is virtual so it will be your file if youfile is in the root of your virtual directory (the directory you have on your host), if the file is in a folder it would be /folder/yourfile.txt (note the forward slash with a virtual include)).
The page doing the including will need to be a .asp page (just rename it and give it a .asp extention).
I basically include everything but content (everything from the doc type to the start of the content and then everything after it) and my page might be just content, depending on what other scripts I have running.
That include code will be where you want the included stuff to go. You can put html in the include file, as what happens is the server just takes all the contents from the include file and slaps them into the file doing the including right where your code is.
Mimorkeris
01-16-2005, 02:31 PM
Thanks, this sounds just to good to be true, I'll give it a try first thing tomorrow.
Could you just clarify if this works if the page uses a CSS file?
Many thanks.
ray326
01-16-2005, 04:28 PM
Originally posted by Mimorkeris
Thanks, this sounds just to good to be true, I'll give it a try first thing tomorrow.
Could you just clarify if this works if the page uses a CSS file?
Many thanks. It'll work fine with CSS.
PeOfEo
01-16-2005, 04:34 PM
Yes, I even include my css imports.
To the viewer the page will not even appear to be one entity because that html from the other file is just put right into the main page before the client even sees it. So browser support is not an issue at all.
Mimorkeris
01-17-2005, 01:28 AM
Brilliant! Just tried it, it works great, thanks.
I have another question, but I'll do new post.
PeOfEo
01-17-2005, 01:40 PM
No problem man