【问题标题】:HTML5 Importing external local html file in index.htmlHTML5 在 index.html 中导入外部本地 html 文件
【发布时间】:2017-03-14 13:33:13
【问题描述】:

早些时候,我设法从我的 index.html 的外部 html 文件中加载 html 代码

<head>
    <link rel="import" href="html/html_snippets.html">
</head>

然后用

找到它
var mySnippet = $(".foo").html();

但现在我开始收到有关 CORS 政策的错误:

Access to Imported resource at 'file:///path/html/html_snippets.html' from origin 'file://' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.

我无法让它工作。

我怎样才能覆盖它,我需要在外部文件中有 html sn-ps 并在启动时加载它们一次,然后再处理它们。

【问题讨论】:

标签: javascript jquery html cors


【解决方案1】:

是的,HTML 可以选择包含 html 文件。语法是这样的

<div w3-include-html="content.html"></div>

<script>
w3IncludeHTML();
</script>

供参考http://www.w3schools.com/howto/howto_html_include.asp

【讨论】:

  • 这似乎有效,但我真的不想使用另一个外部脚本来完成应该简单的事情
猜你喜欢
  • 2018-08-17
  • 2020-07-24
  • 1970-01-01
  • 2019-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-15
  • 2015-09-28
相关资源
最近更新 更多