将外部HTML文件包含在另一个HTML文件中

时间:2013-06-17 13:14:38

标签: html

如何将外部html文件插入我的文件?

例如:

<div id="header">

       Here show the external HTML code in the file, for example: name.html

</div>

非常感谢!

4 个答案:

答案 0 :(得分:37)

另一种方法是使用object标签。这适用于Chrome,IE,Firefox,Safari和Opera。

<object data="html/stuff_to_include.html"> 
    Your browser doesn’t support the object tag. 
</object>

更多信息 http://www.w3schools.com/tags/tag_object.asp

答案 1 :(得分:9)

您可以使用jquery加载。

<script type="text/javascript">
$(document).ready(function(e) {
    $('#header').load('name.html',function(){alert('loaded')});
});
</script>

不要忘记在上面的代码中包含jquery库。

答案 2 :(得分:7)

您正在寻找<iframe>标记,或者更好的是服务器端模板语言。

答案 3 :(得分:1)

iframe element

<iframe src="name.html"></iframe>

但是,您可以更好地处理在多个页面上显示的内容using templates

相关问题