简体   繁体   English

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

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

The script that I am using to import external HTML which has my Bootstrap based Navbar, here is the Javascript: 我用来导入具有基于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>

In my HTML page, all I am doing is including a reference to external html file in section and adding a div in my section with defined class name as follows: 在我的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? HTML5? Internet Exploder? Internet Exploder?
https://caniuse.com/#feat=imports https://caniuse.com/#feat=imports

Nope. 不。

Can use a polyfill like this though: 可以使用这样的polyfill:
https://github.com/webcomponents/html-imports https://github.com/webcomponents/html-imports

Only the Chrome browser supports HTML imports. 仅Chrome浏览器支持HTML导入。 You should use a polyfill for different browsers. 您应该将polyfill用于不同的浏览器。

暂无
暂无

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

相关问题 在Chrome和Firefox中可以使用Canvas元素+ Javascript,而不能在Internet Explorer中使用 - Canvas element + Javascript working in Chrome and Firefox, not in Internet Explorer chrome,firefox和Internet Explorer中的Ajax和html事件 - Ajax and html events in chrome, firefox and Internet Explorer 为什么这在fireFox中有效,但在Chrome或Internet Explorer 9中却无效? - Why is this working in fireFox but not in Chrome or Internet Explorer 9? 元标记中的javascript在Firefox和Internet Explorer上不起作用 - javascript in meta tag not working on firefox and internet explorer Umbraco中的外部JavaScript文件在Internet Explorer中不起作用 - External JavaScript files in Umbraco are not working in Internet Explorer Javascript代码段无法在Chrome中运行,但可在Internet Explorer中使用 - Javascript snippet not working in Chrome, but works in Internet Explorer javascript脚本可在Firefox,Chrome,Safari,Internet Explorer &lt;9,而不是IE 9中运行 - javascript script works in Firefox, Chrome, Safari, Internet Explorer < 9, but not in IE 9 Flot图在Firefox或Internet Explorer中无效,仅适用于Chrome - Flot graph not working in Firefox or Internet Explorer, only Chrome 插入Javascript的元素在Firefox和Chrome中显示/更新,但在Internet Explorer 8中不显示/更新 - Javascript inserted elements appear/update in Firefox & Chrome, but not Internet Explorer 8 Javascript打印弹出窗口适用于Firefox / Chrome但不适用于Internet Explorer - Javascript printing a popup window works in Firefox/Chrome but not Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM