简体   繁体   English

如何处理超过10页的静态页眉/页脚?

[英]How to deal with a static header/footer with 10+ pages?

How do I deal with a static header/footer that doesn't change within my 10+ pages. 我该如何处理10多个页面中不变的静态页眉/页脚。 Keep in mind all these pages share the same header/footer. 请记住,所有这些页面共享相同的页眉/页脚。 So currently If I change one content from the header/footer I would need to go to all other pages in order to make the same changes. 因此,当前,如果我更改页眉/页脚中的一个内容,则需要转到所有其他页面以进行相同的更改。

What I'm hoping to achieve is basically to change once and have the change reflected on all pages. 我希望实现的基本上是一次更改,并将更改反映在所有页面上。

I was thinking of adding the header/footer (HTML) in a .txt file and calling that .txt file JavaScript way. 我正在考虑在.txt文件中添加页眉/页脚(HTML),并以JavaScript方式调用该.txt文件。 But I'm pretty sure its bad practice and a security risk to have html in a .txt file and too call that .txt file through js. 但我很确定,将html包含在.txt文件中并且也通过js调用该.txt文件是一种不好的做法,并且存在安全风险。

You need to create separate header and footer html files and than need to include these files on all pages. 您需要创建单独的页眉和页脚html文件,然后需要在所有页面上包含这些文件。 In this way you can control this. 这样您就可以控制它。

Check below how to include an html file in another html file 检查下面如何在另一个HTML文件中包含一个HTML文件

http://www.w3schools.com/howto/howto_html_include.asp http://www.w3schools.com/howto/howto_html_include.asp

Include another HTML file in a HTML file html-file 在HTML文件 html 文件中包含另一个HTML文件

http://www.hongkiat.com/blog/html-import/ http://www.hongkiat.com/blog/html-import/

Another way you can create php files instead of html and include common php files in another easily 您可以使用另一种方式来创建php文件而不是html,并在另一种轻松包含通用php文件的方法

http://www.w3schools.com/php/php_includes.asp http://www.w3schools.com/php/php_includes.asp

You could use an angular directive. 您可以使用角度指令。

var myApp = angular.module('myApp', []);

myApp.directive('mainNavigation', function(){
  return {
    restrict: 'E',
    templateUrl: 'partials/navigation.html'
  }
});

Then you would use ng-app="myApp to call angular and then include the directives in the areas you need them. In this case you would have: 然后,您可以使用ng-app="myApp调用angular,然后将指令包含在所需的区域中。在这种情况下,您将拥有:

<main-navigation></main-navigation>

You could use jQuery's .load() function. 您可以使用jQuery的.load()函数。

Just keep in mind this will add two additional calls to the server on every page request. 请记住,这将在每个页面请求上向服务器添加两个额外的调用。 ( api.jquery.com/load ) api.jquery.com/load

 // add this snippet somewhere in your page (inside <script> tags) $(function() { $("header").load("header-url"); $("footer").load("footer-url"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <header> Header </header> <hr/> <div id="content"> static page content goes here </div> <hr/> <footer>copyright</footer> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 ejs 或 header 和页脚模板用于 static 托管与 github 页面? - Use ejs or header and footer templates for static hosting with github pages? 如何检测IE 10+的onerror事件 - How to detect IE 10+ for an onerror event 如何在JS中为网页创建动态页眉和页脚? - How to create Dynamic Header and footer for web pages in JS? 如何制作页眉和页脚而不重复打印N页? - How to make the header and footer without repeating in print for N pages? 如何一次将相同的页眉和页脚添加到所有页面? HTML - How to add the same header and footer to all pages at once? HTML 如何在 static ZFC35FDC70D5FC69D269883A82EZC 页面中使用默认 wordpress header 和页脚 - how to use default wordpress header and footer in static html page 如何在Internet Explorer 10+中检测点击次数 - How do I detect the number of clicks in Internet Explorer 10+ 如何动态优化在页面上加载10张以上全尺寸图像? - How to optimize loading 10+ full size images on a page dynamically? 如何在 Angular 10+ 中使用模块路由而不是组件 - How to use routing with module instead of component in Angular 10+ 如何获取 Angular (10+) 中的所有复选框值? - How to get all checkboxes values in Angular (10+)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM