【发布时间】:2023-05-11 03:39:01
【问题描述】:
据此article, 可以在除最新版本的 Chrome 之外的浏览器上通过 Polymer 使用 HTML 导入(这可能是目前唯一启用 HTML 导入的浏览器)。但是,使用以下 html,改编自同一篇文章:
1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Basic HTML Imports</title>
<!-- Pull in our blog post example -->
<link rel="import" href="2.html">
</head>
<body>
<p>Hello World!</p>
<script src="platform.js"></script>
<script>
window.addEventListener('HTMLImportsLoaded', function() {
var link = document.querySelector('link[rel=import]');
var content = link.import.querySelector('#test');
document.body.appendChild(document.importNode(content, true));
});
</script>
</body>
</html>
2.html
<div id="test">
<h1>Here is the Import </h1>
</div>
我收到了following result。
<div id="test"> 似乎在 Firefox 中成功导入,但在 Chrome 中没有。请注意,我尝试在 about:flags 中启用实验性 Web 平台功能。
有没有办法让它也适用于 Chrome?我正在寻找任何能够让我在最新版本的 Firefox 和 Chrome 中使用基本导入的解决方案。 (我的项目要到 2016 年初才能上线,所以我希望届时将在每个平台上提供标准支持,但在此期间解决方法会很好。)谢谢。
【问题讨论】:
-
这就是他们在这里的样子:w3.org/TR/html-imports/#link-type-import
-
嗯,请原谅我的评论,因为我通常为此使用 PHP :)
标签: html google-chrome polymer