有没有办法将HTML导入HTML文件? [英] Is there a way to import HTML into an HTML file?

查看:96
本文介绍了有没有办法将HTML导入HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过在这里和Google上寻找此内容,但是我还没有真正找到这个特定问题的答案,因此我不确定是否有某些内容-一个术语或一些我需要寻找的内容,因此抱歉,这是一个常见问题.

I've tried looking for this on here and on google but I haven't really found an answer to this specific question and I'm not sure if there's something - a term or something that I need to look for, so I apologize if this is a commonly asked question.

无论哪种方式,例如,我正在构建一个包含很多部分的网站,并且我希望这些部分是模块化的,因此每个部分都是自己的html文件.因此,基本上,我可以在主要html文件中的任何位置包含这个小模块,或者我可以简单地将导航栏和页脚包含在其他HTML页面上,而不必重写代码行.

Either way, let's say for example that I'm building a website with many sections and I wanted these sections to be modular, so each section is it's own html file. So basically I could include this little module anywhere I want on the main html file or maybe I could simply include navbars and footers onto other HTML pages without having to rewrite lines of code.

仅HTML就有可能吗?

Is this possible with just HTML alone?

推荐答案

值得探讨的一个选项是 object 标记.您可以在页面上包含另一个文件(任何类型).

An option worthwhile exploring is the object tag. You can include another file (of any kind) onto your page.

与下面的其他选项相比,这似乎是一个更合适的选项.

This seems like a more suitable option compared to the rest of options below.

< object type ="text/html" data ="file.html"></object>

它的工作原理与HTML5导入类似.

It works on similar basis as HTML5 Import.

object 标记是HTML 4的一部分,因此它是受支持,因为IE6 +,Firefox 2 +,Chrome 1+等.

The object tag is part of HTML 4 therefore it's supported since IE6+, Firefox 2+, Chrome 1+ etc.

使用 HTML5导入.它确实实施它的支持/浏览器非常有限.

< link href ="extern.html" rel ="import"/>

除此之外,如果要从客户端执行操作,则至少需要Javascript才能导入另一个文件.后端的功能多种多样,具体取决于您的技术.

Other than that you will need Javascript at bare minimum to import another file if you want to do it from client-side. There are variety of options available to do it from back-end depending on your tech.

Pete强调的另一种可能性是使用 iframes (尽管我不希望使用它们).

Another possibility as Pete highlighted is the use of iframes (although I would prefer not to use them).

强烈建议您不要在此处上看到HTML5 Imports的使用.

The use of HTML5 Imports is highly discouraged as you can see on here.

以下是从以上链接中摘录的一些笔记:

Here's few notes taken from the above link:

  • MS Edge状态:正在考虑

  • MS Edge status: Under Consideration

Chrome状态:已弃用

Chrome status: Deprecated

Firefox状态:未计划

Firefox status: not-planned

WebKit状态:不考虑

WebKit status: Not Considering

Firefox尚无计划支持HTML导入,尽管目前可以通过about:config

Firefox has no plans to support HTML imports though for now it can be enabled through the "dom.webcomponents.enabled" preference in about:config

这篇关于有没有办法将HTML导入HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆