Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make header and footer files to be included in multiple html pages

I want to create common header and footer pages that are included on several html pages.

I'd like to use javascript. Is there a way to do this using only html and JavaScript?

I want to load a header and footer page within another html page.

like image 392
Prasanth A R Avatar asked Sep 10 '13 06:09

Prasanth A R


People also ask

How do I reuse header and footer in HTML?

You could place your footer HTML in a separate file, and then use javascript to load the HTML content of that file, and append it to a div in your page. Show activity on this post. Place your code in some html file and then use jquery to include in the file you want.

HOW include header and footer in HTML file in PHP?

Besides just using include() or include_once() to include the header and footer, one thing I have found useful is being able to have a custom page title or custom head tags to be included for each page, yet still have the header in a partial include.


1 Answers

You can accomplish this with jquery.

Place this code in index.html

<html> <head> <title></title> <script     src="https://code.jquery.com/jquery-3.3.1.js"     integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="     crossorigin="anonymous"> </script> <script>  $(function(){   $("#header").load("header.html");    $("#footer").load("footer.html");  }); </script>  </head> <body> <div id="header"></div> <!--Remaining section--> <div id="footer"></div> </body> </html> 

and put this code in header.html and footer.html, at the same location as index.html

<a href="http://www.google.com">click here for google</a> 

Now, when you visit index.html, you should be able to click the link tags.

like image 163
Hariprasad Prolanx Avatar answered Sep 18 '22 14:09

Hariprasad Prolanx