我的脚本在下面给出错误
未捕获的TypeError:无法读取未定义的属性“parentNode”
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName[0];
if (d.getElementById(id)) return;
js = d.createElement; js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";
fjs.parentNode.insertBefore(js,fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
查看部分是
<blockquote cite="url">
<a href="url"></a>
</blockquote>
</div>
答案 0 :(得分:0)
使用tagName
函数时需要传递getElementsByTagName()
,因此请使用
fjs = d.getElementsByTagName(s)[0]
而不是
fjs = d.getElementsByTagName[0]
答案 1 :(得分:0)
<script>
(function(document, s, id) {
let js;
const id = id;
const ref = document.getElementsByTagName('script')[0];
if (document.getElementById(id)) {
return;
}
js = document.createElement('script');
js.id = id;
js.async = true;
js.src = '//connect.facebook.net/en_US/sdk.js';
ref.parentNode.insertBefore(js, ref);
}(document, 'script', 'facebook-jssdk'));
</script>
答案 2 :(得分:0)
更改版本
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName[0];
if (d.getElementById(id)) return;
js = d.createElement;
js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5';
fjs.parentNode.insertBefore(js,fjs);
}(文档,&#39;脚本&#39;,&#39; facebook-jssdk&#39;));