I have a navigation bar for my website:
Update @AlienWebguy pointed out that these solutions will hurt your rankings in search engine results. If you care about that, don't use them. But in my opinion, as valid options, they are worth knowing about.
If a server-side include (using PHP or some other language) is not an option you could do it using :
Frames
In all your pages, include an iframe (styled to be without borders or scrollbars) and set the src
to be an HTML file that holds your navigation markup. Of course, you're going to run in trouble with following links and you'll probably have to resort to JavaScript in order to get the 'right' behaviour. This is probably not worth the effort. To follow the links correctly, you'll need to use the target attribute in your navigation links to _top
(or perhaps _parent
). This is probably the simplest solution that should work even in user agents without scripting support.
For example, your page will look like this:
with navbar.html looking like this:
Ajax
Save the HTML you need for the navbar in the form of an HTML fragment (not a complete HTML document) and load it using ajax on page load.
Here's an example using jQuery. On your page:
navbar.html