【问题标题】:link rel import not working in Mozila Firefox链接 rel 导入在 Mozilla Firefox 中不起作用
【发布时间】:2019-03-03 05:55:02
【问题描述】:

我有一个问题。我想像下面这样调用 HTML 文件。但它只能在 Google chrome 中工作。在 Mozila Firefox 中它根本不工作。

<link rel="import" href="controllerHTML/adminController.html"> 

adminController.html:

<script src="../controller/loginController.js" type="text/javascript"></script>
    <script src="../controller/adminController.js" type="text/javascript"></script>
    <script src="../controller/adminCollegeProfileController.js" type="text/javascript"></script>
    <script src="../controller/adminResController.js" type="text/javascript"></script>
    <script src="../controller/adminResourceUserRoleController.js" type="text/javascript"></script>
    <script src="../controller/adminResourceClassController.js" type="text/javascript"></script>

这里我的要求是我需要在我的 index.html 的正文部分调用这个 adminController.html 文件。这个 adminController.html 文件包含一些动态包含的 js 链接。但它只在 Chrome 中工作。请帮我解决这个问题。

【问题讨论】:

  • 您是否使用任何框架,如 AngularJS 或库,如 jQuery?还是您正在寻找香草 JS 中的解决方案?
  • @FelisCatus:我正在使用 angular.js。因为我有这么多控制器文件,我不想将所有文件都包含在索引页面中。我想通过保留在另一个页面中来调用它们。
  • 在这种情况下,最好打开另一个问题,重点关注角度控制器动态加载和类似的东西,因为那将是一个完全不同的主题。让我们在这里继续讨论 HTML 导入。
  • 好的,我会关注另一个问题。

标签: html css firefox


【解决方案1】:

HTML 导入仍然是 relatively new technology in W3C Working Draft。它们可能需要一段时间才能被浏览器采用。

自 2015 年 11 月起,HTML 导入在 Chrome 中默认启用,但仅在 Firefox 中的标志后面可用。更多详情和相关问题请查看the support table

【讨论】:

  • @FelisCatus:好的,我已经读过这张表了。现在最好避免这种方式。你能建议我动态包含 js 链接的最佳方法是什么。我正在更新@987654323 @文件在我的帖子中。
  • 请查看我的帖子。
【解决方案2】:

Mozilla 有 no intentions 来支持未来的导入,因为他们专注于 Web 组件:

Firefox 不会提供 HTML 导入。有关更多信息,请参阅this Hacks blog post。您仍然可以通过启用 dom.webcomponents.enabled 标志在 Firefox 中使用 HTML 导入。如果您不想启用该标志,则可以使用诸如 Google 的 webcomponents.js 之类的 polyfill。

按照他们的建议,您可以改用Google's webcomponents.js

一些浏览器仍在更新过程中以支持 Web 组件的标准。同时,polyfill 尽可能地模拟缺失的浏览器功能。

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 2018-10-18
    • 1970-01-01
    • 2018-07-21
    相关资源
    最近更新 更多