JavaScript 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.

Answer:1

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>\
);
Answer:2

The easiest way would just be to write the code in a JS file, and include that code on your pages. You can hard code it or make it more intelligent, but here's a basic demo.

var html = '<ul>\
              <li>\
                <a target='_blank' href="#">link</a>\
              </li>\
              <li>\
                <a target='_blank' href="#">link</a>\
              </li>\
              <li>\
                <a target='_blank' href="#">link</a>\
              </li>\
            </ul>';

document.getElementById('nav').innerHTML = html;
<nav id="nav"></nav>
Answer:3

I'm looking for a solution in Polymer that includes the following features: sign in sign up forgot password reset password change password social sign-in via Facebook social sign-in via Google secure ...

I'm looking for a solution in Polymer that includes the following features: sign in sign up forgot password reset password change password social sign-in via Facebook social sign-in via Google secure ...

  1. what is similar solution
  2. what is self similar solution
  3. what's similar to contact solution
  4. what is similar between solution and colloid

I am very new to angular 2 I am stuck here where i have to display an image for which I'm using relative path­­­­­­­­­­­­­­­­­­­­ <img src="./../images/publicVideo1.PNG"> but getting the ...

I am very new to angular 2 I am stuck here where i have to display an image for which I'm using relative path­­­­­­­­­­­­­­­­­­­­ <img src="./../images/publicVideo1.PNG"> but getting the ...

  1. display image using matplotlib
  2. display image using javascript
  3. display image using css
  4. display image using pillow
  5. display image using php
  6. display image using opencv
  7. display image using json
  8. display image using cv2
  9. display image using jquery ajax
  10. display image using pil python
  11. display image using applet
  12. display image using jquery
  13. display image using pil
  14. display image using html
  15. display image using opencv python
  16. display image using python
  17. display image using flask
  18. display image using tkinter
  19. display image using ajax
  20. display image using java

I am trying to send an by the user dropped file to the php upload script using ajax. I don't know why it doesn't work, nothing happens if I drop an image. (Why's no one answering?) So this is the ...

I am trying to send an by the user dropped file to the php upload script using ajax. I don't know why it doesn't work, nothing happens if I drop an image. (Why's no one answering?) So this is the ...

  1. sending file upload via ajax
  2. file upload sending
  3. send file upload via ajax jquery

The options for configuring the GetHTTP processor look like they would work for connecting to a third party API. I need to send the username (available), password (available) and a 3rd string value ...

The options for configuring the GetHTTP processor look like they would work for connecting to a third party API. I need to send the username (available), password (available) and a 3rd string value ...

  1. nifi processor
  2. nifi processor list
  3. nifi processor example
  4. nifi processor logs
  5. nifi processor scheduling
  6. nifi processor concurrent tasks
  7. nifi processor development
  8. nifi processor group
  9. nifi processor run schedule
  10. nifi processor lifecycle
  11. nifi processor properties
  12. nifi-processor-bundle-archetype
  13. nifi processor requires upstream connection
  14. nifi processor documentation
  15. nifi processor replace text example
  16. nifi processor state
  17. nifi processor github
  18. nifi processor api
  19. nifi processor group variables
  20. nifi processor run once