Tuesday, October 25, 2011

How do I link to an external navigation bar on all of my pages?

I know you can do this with stylesheets, but I need to know the code for navigation bars or images.



the code for style sheets looks something like this





%26lt;LINK href=%26quot;yourstylesheet.css%26quot; rel=%26quot;stylesheet%26quot; type=%26quot;text/css%26quot;%26gt;



That's all fine and dandy, but I need to put a good navigation on my website and be able to edit it without having to go through and edit each individual page.





Basically, i'd create the navigation bar and upload it in a separate file, then link to it from all of my pages. If I need to change a link or something, i'd change the file, not every single page. I just need to know the code to do this with! HELPHow do I link to an external navigation bar on all of my pages?There are several ways including PHP, ASP, SSI, javascript.



1- For plain HTML, use javascript. Copy and paste the following into a text editor (edit to fit your needs):



document.write(%26quot;%26lt;a href='home.htm'%26gt;Home%26lt;/a%26gt;%26lt;br%26gt;%26quot;);

document.write(%26quot;%26lt;a href='contact.htm'%26gt;Contact%26lt;/a%26gt;%26lt;br%26gt;%26quot;);

document.write(%26quot;%26lt;a href='links.htm'%26gt;Links%26lt;/a%26gt;%26lt;br%26gt;%26quot;);





Save this as menu.js



2- In your HTML files, insert the following code at the point you want the menu to appear:



%26lt;SCRIPT LANGUAGE=%26quot;JavaScript%26quot; SRC=%26quot;menu.js%26quot;%26gt;%26lt;/SCRIPT%26gt;How do I link to an external navigation bar on all of my pages?You can use frames heres an example that would have a total of three frames on the page 2 on the right and on large on one the left



%26lt;!DOCTYPE HTML PUBLIC %26quot;-//W3C//DTD HTML 4.01 Frameset//EN%26quot;

%26quot;http://www.w3.org/TR/html4/frameset.dtd?br>
%26lt;HTML%26gt;

%26lt;HEAD%26gt;

%26lt;TITLE%26gt;A simple frameset document%26lt;/TITLE%26gt;

%26lt;/HEAD%26gt;

%26lt;FRAMESET cols=%26quot;20%, 80%%26quot;%26gt;

%26lt;FRAMESET rows=%26quot;100, 200%26quot;%26gt;

%26lt;FRAME src=%26quot;contents_of_frame1.html%26quot;%26gt;

%26lt;FRAME src=%26quot;contents_of_frame2.gif%26quot;%26gt;

%26lt;/FRAMESET%26gt;

%26lt;FRAME src=%26quot;contents_of_frame3.html%26quot;%26gt;

%26lt;NOFRAMES%26gt;

%26lt;P%26gt;This frameset document contains:

%26lt;UL%26gt;

%26lt;LI%26gt;%26lt;A href=%26quot;contents_of_frame1.html%26quot;%26gt;Some neat contents%26lt;/A%26gt;

%26lt;LI%26gt;%26lt;IMG src=%26quot;contents_of_frame2.gif%26quot; alt=%26quot;A neat image%26quot;%26gt;

%26lt;LI%26gt;%26lt;A href=%26quot;contents_of_frame3.html%26quot;%26gt;Some other neat contents%26lt;/A%26gt;

%26lt;/UL%26gt;

%26lt;/NOFRAMES%26gt;

%26lt;/FRAMESET%26gt;

%26lt;/HTML%26gt;How do I link to an external navigation bar on all of my pages?Or try server-side includes. You put:

%26lt;!--#include virtual=%26quot;/includes/mynavbar.html%26quot;--%26gt; and the server automatically loads the contents of mynavbar.html into that part of the page before sending it to the browser. The page you are making it be included in has to be marked to be interpreted by the server. Either the server configuration can be modified to interpret all .html files or you can use .shtml on the ones which are including another file.



The thing server-side includes have over Javascript is that many security-conscious folks disable Javascript, so they wouldn't get to see your menu at all if they do that. Neither would people using text-based browsers like lynx. You have no control over how the person's browser is setup. You presumably do have some control over the server (or at least can guarantee that it won't change for every user).