将外部 HTML 文件包含到另一个 HTML 文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17148357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including external HTML file to another HTML file
提问by user2467899
How can I insert an external html file to my file?
如何将外部 html 文件插入到我的文件中?
For instance:
例如:
<div id="header">
Here show the external HTML code in the file, for example: name.html
</div>
Thank you very much!
非常感谢!
回答by Stuart G
Another way is to use the object tag. This works on Chrome, IE, Firefox, Safari and Opera.
另一种方法是使用对象标签。这适用于 Chrome、IE、Firefox、Safari 和 Opera。
<object data="html/stuff_to_include.html">
Your browser doesn't support the object tag.
</object>
more info at http://www.w3schools.com/tags/tag_object.asp
回答by Rajnikant Kakadiya
You can use jquery load for that.
您可以为此使用 jquery 负载。
<script type="text/javascript">
$(document).ready(function(e) {
$('#header').load('name.html',function(){alert('loaded')});
});
</script>
Don't forget to include jquery library befor above code.
不要忘记在上面的代码之前包含 jquery 库。
回答by SLaks
You're looking for the <iframe>
tag, or, better yet, a server-side templating language.
您正在寻找<iframe>
标签,或者更好的是,一种服务器端模板语言。
回答by Quentin
The iframe element.
在iframe元素。
<iframe src="name.html"></iframe>
But content that you way to have appear on multiple pages is better handled using templates.
但是使用模板可以更好地处理您在多个页面上显示的内容。