简体   繁体   English

导入包含脚本标记的外部 html - 不起作用

[英]Import external html containing script tag - doesn't work

I have an index.html我有一个index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>MyApp</title>
  <link rel="import" href="./common.html">
</head>
<body>
  <app-root></app-root>
</body>
</html>

and an external HTML file common.html which contains a script tag和一个包含脚本标签的外部 HTML 文件common.html

<script>
  window.MY_APP = {
    MY_SETTINGS: {}
  }
</script>

As you can see I am importing common.html in index.html .如您所见,我正在index.html导入common.html The problem is that MY_APP becoming undefined after a successful render of index.html.问题是MY_APP在成功渲染 index.html 后变得未定义。 I could see success call to common.html file in the network tab(Testing in Chrome browser - V 80.**).我可以在网络选项卡中看到成功调用 common.html 文件(在 Chrome 浏览器中测试 - V 80.**)。

This used to work seamlessly earlier but now broken.这以前可以无缝地工作,但现在已经坏了。

Did anyone face this problem?有没有人遇到过这个问题? or does anyone know what is happening?或者有谁知道发生了什么? Thanks in Advance.提前致谢。

HTML imports were recently depreciated by Chrome, which would explain why this used to work for you and doesn't any longer. HTML 导入最近被 Chrome 折旧,这可以解释为什么这曾经对您有用而不再适用。

https://www.chromestatus.com/feature/5144752345317376 https://www.chromestatus.com/feature/5144752345317376

In the decision thread they mention polyfills and something called Shadow DOM V0, so those might be alternatives for you.在决策线程中,他们提到了 polyfills 和称为 Shadow DOM V0 的东西,因此这些可能是您的替代品。

This feature was Chrome-specific so it was removed.此功能是 Chrome 特定的,因此已被删除。

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

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