Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single navigation bar across website?

I am currently building a web application for my employer, but I have some restrictions. It has to be in HTML, CSS, and Javascript for the front end, and I have to use a lot of different pages for this, each sharing the same navigation bar.

If the navigation is the same for each page, is it possible to write the navigation bar once and use it across the entire website? I am just annoyed when I make a change to a link or something and I have to run through and change each pages respective navigation link. Normally I'd use something like Angular to achieve this, but I am not sure how to do it with this more barebones approach. They really don't use any JS libraries either so if there's a way to do it with "raw" HTML CSS and JS I'd love to learn how this works if it exists.

like image 326
Jarred Parr Avatar asked Jun 12 '17 14:06

Jarred Parr


People also ask

What is the navigation bar on a website called?

Your website's navigation bar (sometimes known as nav bar) is often the first touchpoint your visitors interact with to guide them to specific products or categories. So it's crucial to ensure your navigation bar is as helpful and engaging as possible.

Can you have 2 nav bars HTML?

Yes, absolutely. You can have multiple header , nav , and footer tags sans penalty.


1 Answers

JQuery

As JQuery is JS-based, you might be allowed to use it. You could then add a navigation div into each page's template:

<div id="navigation"></div>

and include a script on each page that executes the following JQuery-code:

$(function() {
    $("#navigation").load("navigation.html");
});

Pure JavaScript

Alternatively, if you cannot use JQuery whatsoever, you could use plain JavaScript, which is more lightweight but not as clean.

Wherever you want to include the navigation, simply include a script:

<script src="nav.js"></script>

Which holds your navigation based on document.write:

document.write('<div>\
    ... your navigation content ...\
    </div>\
');
like image 92
N. M. Avatar answered Oct 13 '22 21:10

N. M.