(No Programming) Use JavaScript to Load Header and Footer Templates. Works Just Like PHP Include

I’ve looking for this for years, but it’s actually much simpler than I thought. You can build your HTML website with universal header and footer (so you don’t have to repeat update multiple files over and over again) by adding a simple JavaScript/Jquery line without using any programming PHP scripts.

HTML

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function(){
$("#header-template").load("header.html");
$("#footer-template").load("footer.html");
});
</script>

<div id="header-template"><!--Your header.html placeholder--></div>

<!--Your content start here-->
Hello World!
<!--Your content end here-->

<div id="footer-template"><!--Your footer.html placeholder--></div>

Instruction

  1. Create a header.html and put all the header portion starting with <!DOCTYPE html>.
  2. Create a footer.html and put all the footer portion end with </html>.
  3. Create a index.html and copy and paste the HTML code (from the top of this article) into your HTML document.
  4. Build your own content by replacing the text “Hello World!” and save.
  5. Open the index.html and review yourself.

You can duplicate the index.html and rename it differently for any additional pages you wish to create. This JavaScript works on a server environment, so this will not be able to load header and footer if you are opening the files from your desktop which means you need to upload your files via FTP and access your HTMLs live.

Now, you’ve created a website without using any programming scripts.

2 thoughts on “(No Programming) Use JavaScript to Load Header and Footer Templates. Works Just Like PHP Include

Leave a Reply

Your email address will not be published. Required fields are marked *