我想知道如何将标头(或只是任何html文件)添加到另一个html文件中。我尝试使用iframe,但是它只是重定向了iframe内部。一旦完成我的网站,我可能会有很多页面,因此仅添加一个头文件即可更改标题,这将非常有用,只需更改一个文件即可,而不必在所有页面上都进行更改。有谁知道如何做到这一点?提前致谢。
使用jQuery:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#includedContent").load("b.html");
});
</script>
</head>
<body>
<div id="includedContent"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用没有jQuery的JavaScript:
<html>
<body>
<script src="b.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
b.js:
document.write('\
\
<h1>This is my include file</h1>\
\
');
Run Code Online (Sandbox Code Playgroud)
使用PHP:
<?php include('b.html');?>
Run Code Online (Sandbox Code Playgroud)
为此,您可能必须修改Web服务器上的.htaccess文件,以便php可以在.html文件中解释。您应该在.htaccess文件中看到或添加以下内容:
RemoveHandler.html
AddType application/x-httpd-php .php .html
Run Code Online (Sandbox Code Playgroud)
带有服务端包含(SSI):
<!--#include virtual="a.html" -->
Run Code Online (Sandbox Code Playgroud)
使用HTML5:
<object name="foo" type="text/html" data="foo.inc"></object>
Run Code Online (Sandbox Code Playgroud)
或者:
<embed type="text/html" src="foo.inc">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15268 次 |
| 最近记录: |