我正在尝试按照https://www.webcomponents.org/polyfills/中的说明填充 webcomponents,因为我希望我的示例应用程序可以在 Chrome 和 Firefox 上运行。但是我收到ReferenceError: customElements is not defined在 Firefox 中的错误。在 index.html 上查看我的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Sample</title>
<link rel="stylesheet" href="css/site.css">
<!-- Components -->
<link rel="import" href="components/global/site-navigation.html">
</head>
<body>
<script>
(function () {
if ('registerElement' in document
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
// platform is good!
} else {
// polyfill the platform!
var e = document.createElement('script');
e.src = 'js/webcomponents.js';
document.body.appendChild(e);
}
})();
</script>
<site-navigation></site-navigation>
</body>
</html>
我错过了什么?
PS:在 Chrome 中一切正常(有/没有 polyfill)