Repeat same HTML code in several pages

独自空忆成欢 提交于 2019-12-05 06:13:32

Have a look at server side includes ... create a menu.shtml page and then include it like so :

<!--#include virtual="/menu.shtml" -->

Its supported by most web servers out of the box (including IIS, Apache and lighttpd)

madhairsilence

Have you heard about MasterPage Concept

The below link will give you a quick start

Master page are pages which will act as a frame for all other pages. You have to write it only one. And each page that is coming under that, will have to include the master page. Thats all!

You can do this with jquery

Assume you have page1.html page2.html etc.

You want in each of these pages your contactinfo. You can create a file with the name "info.txt". On the spot where you want this contact info, you put a div. as shown in this example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <!-- page content -->
    <div id="contact"></div>
  </body>
</html>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

<script>
$(document).ready(function(){
        $("#contact").load("info.txt");
    ;
});
</script>

Whatever you place in 'info.txt' will be put on the spot of were you put

You could write a simple bit of js in an external file and then call it in each page to dynamically load the menu. You can then simply edit the menu by editting the JS file. all you'd need to do then is include the in the html and use document.getElementById("menu").innerHTML = menuHTML; where menuHTML is a variable containing the pure HTML code of the menu. You can then include the JS file and call it in the body onload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!