gpt4 book ai didi

javascript - 使用 webcomponenetsjs 的 HTMLImports 以意外的执行顺序加载导入 - firefox

转载 作者:行者123 更新时间:2023-11-27 23:29:29 25 4
gpt4 key购买 nike

我是 webcomponenetsjs 的新手,我一直在尝试使用 HTMLImports 将另一个 HTML 导入到我的 index.html 中。由于 chrome 支持 HTML 导入,因此我没有问题。但是当我尝试使用 firefox 时,HTML 导入无法按预期工作。问题是它加载了所有的 HTML 元素,加载了所有的脚本,然后只加载了 |link rel="import"|开始执行导入。为了更清楚地说明,以下是触发警报的顺序:

1.在 vendor 之后
2。在导入之前
3. vendor.js 中的警报
4. test.html 中的警报。

默认情况下,html 导入的执行类似于

1.vendor.js 中的警报
2。在 vendor 之后
3. 在 import.js 之前
4. test.html 中的警报。

当然,它在 chrome 中的工作顺序相同。对于我所缺少的任何帮助,我们将不胜感激。

<html>

<head>
<meta charset="utf-8">
<title>test</title>
<link rel="icon" type="image/ico" href="/images/favicon.ico"/>
<script src="lib/webcomponentsjs/HTMLImports.js"></script>
<link rel="import" href="js_imports/vendorjs.html">
<script>alert("after vendor");</script>

<b>
</head>

<body class="side-nav-collapsed">
<script>alert("before import");</script>
<link rel="import" href="test.html">

</body>

</html>

最佳答案

这是因为 Firefox 使用了 HTMLImports.js polyfill,<link>因此调用是异步的。

对于在 IE 或 Edge 中也出现的此问题的解决方案:HTML imports load order in Internet Explorer

关于javascript - 使用 webcomponenetsjs 的 HTMLImports 以意外的执行顺序加载导入 - firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com