How can we avoid repeating the header and footer code on each html page

I have ten html pages, each page has the same header and footer tag, I have one full page header and footer, and I will link to this page from other html pages.

+2
source share
5 answers

You do this using a server-side language, such as PHP or another of many different languages, that processes the page. Something like that:

<?php include 'header.html'; ?> ... page contents... <?php include 'footer.html'; ?> 
+4
source

If you don’t like users who have JavaScript disabled or using some mobile platforms, you can use JavaScript to do this.

headerfooter.js

 window.onload = function () { var header = document.getElementById('header'); var footer = document.getElementByID('footer'); header.innerHTML = "<h1>My website</h1><h2>Rules</h2>"; footer.innerHTML = "<small>This code is in the public domain</small>"; } 

page.html

 <html> <head> <script type="text/javascript" src="headerfooter.js"></script> </head> <body> <div id="header"></div> ... Your content ... <div id="footer"></div> </body> </html> 

But do not do this, he is unfriendly and unprofessional. Just stick to either using php or creating a solid template that you don't need to edit much later.

+5
source

What is the server scripting language? You can do the so-called "include".

The exact syntax depends on the language (s) supported by your web server.

+1
source

Assuming the "master-pages" tag in the question refers to ASP.NET, here is Super Link . Ps. You should give Ruby on Rails a try :)

+1
source

Use Django . Best there when you hang it :)

0
source

Source: https://habr.com/ru/post/1384074/


All Articles