gpt4 book ai didi

javascript - "Cannot read property ' appendChild ' of null"与 Backbone 网站上的 Disqus

转载 作者:数据小太阳 更新时间:2023-10-29 05:41:15 24 4
gpt4 key购买 nike

我在 Backbone 上有一个网站。当我尝试执行 Disqus 代码时,我得到了

Uncaught TypeError: Cannot read property 'appendChild' of null

我该如何解决?为什么会这样?

var disqus_shortname = 'mysite';

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();

控制台:

undefined
embed.js:1 Unsafe attempt to redefine existing module: BASE
embed.js:1 Unsafe attempt to redefine existing module: apps
embed.js:1 Unsafe attempt to redefine existing module: get
...

embed.js:1 Unsafe attempt to redefine existing module: configAdapter
embed.js:1 Unsafe attempt to redefine existing module: removeDisqusLink
embed.js:1 Unsafe attempt to redefine existing module: loadEmbed
embed.js:1 Unsafe attempt to redefine existing module: reset
embed.js:1 Uncaught TypeError: Cannot read property 'appendChild' of null

最佳答案

对于那些在 2015 年才发现这个问题的人来说,除了缺少“head”或“body”时会发生此错误外,当页面中某处没有以下 div 时也会发生此错误:

<div id="disqus_thread"></div>

将该 div 放在您希望 disqus 线程实际出现的位置。

关于javascript - "Cannot read property ' appendChild ' of null"与 Backbone 网站上的 Disqus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30575237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com