繁体   English   中英

包含外部HTML的JavaScript在Chrome中运行,但在Internet Explorer和Firefox中不起作用

[英]JavaScript to include external HTML is working in Chrome but not in Internet Explorer and Firefox

我用来导入具有基于Bootstrap Navbar的外部HTML的脚本,这是Javascript:

<script type="text/javascript">
var link = document.querySelector('link[rel="import"]');

// Clone the <template> in the import.
var template = link.import.querySelector('template');

var clone = document.importNode(template.content, true);

document.querySelector('#navBar').appendChild(clone);

</script>

在我的HTML页面中,我要做的就是在本节中包括对外部html文件的引用,并在本节中添加具有已定义类名的div,如下所示:

<!— link of external HTML file in <HEAD> section -->
<link rel="import" href="navbar.html">

<!— Div with defined class name “navBar”in <BODY> section -->
<div id="navBar"></div>

HTML5? Internet Exploder?
https://caniuse.com/#feat=imports

不。

可以使用这样的polyfill:
https://github.com/webcomponents/html-imports

仅Chrome浏览器支持HTML导入。 您应该将polyfill用于不同的浏览器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM