【发布时间】:2019-06-11 02:32:39
【问题描述】:
我编写了一个 WordPress 插件,它提供向标题添加脚本。当我尝试添加我们服务的代码 sn-ps 时
<script src="url/index.js"></script>
<script>
var foo = new window.Name("token");
foo.init();
</script>
首先,我遇到了一些错误。
Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
at r.<anonymous> (index.js:176)
at L (index.js:47)
at Generator._invoke (index.js:47)
at Generator.t.(:8000/anonymous function) [as next] (url/index.js:47:4580)
at r (index.js:174)
at c (index.js:174)
at index.js:174
at new Promise (<anonymous>)
at new r (index.js:36)
at r.<anonymous> (index.js:174)
和
Uncaught TypeError: Cannot read property 'appendChild' of null
at i.value (index.js:178)
at r.value (index.js:180)
at (index):41
.
url 返回我们由 Babel 渲染的脚本代码。
当我在脚本前添加任何标准 html 代码,如 <html></html> 或 <p></p>,
<p></p>
<script src="url/index.js"></script>
<script>
var foo = new window.Name("token");
foo.init();
</script>
效果很明显。任何html代码呢?我无法理解。我通过添加<html></html> 来解决它,而不会损坏网站。我尝试学习问题。
【问题讨论】:
标签: javascript html wordpress plugins header