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.
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.
Yes, absolutely. You can have multiple header , nav , and footer tags sans penalty.
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");
});
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>\
');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With