Avoid repeating headers & footers

∥☆過路亽.° 提交于 2019-12-11 07:27:24

问题


I am building a website with at least 7 pages and am looking for a way to avoid having to repeat all headers & footers etc. on every single html document.

I know there are frames and iframes but some browsers don't support these and I want to do something more efficient and flexible for updates. Any ideas/suggestions?


Thanks for the information guys! I'll be sure to try them out. One more thing is that I have a login form within my header. Will these methods affect it?

Regards


回答1:


Yes, server side includes are the way to go, just a few clarifications:

1) You can do it as described by Sotiris if you choose to use PHP - which is very common choice, and btw.virtually all hosts support php.

2) Although the file will have extension .php, you can put your pure html code in it.

3) To be able to test and see this on your computer before uploading it, you have to install server on it. At this point I think it's simplest and fastest for you to go for some ready made solution - these are downloadable free:

http://www.wampserver.com/en/ (for Windows)

http://www.mamp.info/en/index.html (for Mac)

http://tuxtweaks.com/2010/04/installing-lamp-on-ubuntu-10-04-lucid-lynx/ (for Linux)




回答2:


you can create a php file that will include all required code (for example footer.php). Then you can link it adding in every page in the proper place the following code (if you want to add the footer for example):

<?php include "footer.php"; ?>



回答3:


If it is static HTML pages that you are builing, you probably want to think about Server Side Includes

http://en.wikipedia.org/wiki/Server_Side_Includes



来源:https://stackoverflow.com/questions/6249825/avoid-repeating-headers-footers

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