gpt4 book ai didi

javascript - Facebook 分享社交插件的 javascript 代码错误

转载 作者:行者123 更新时间:2023-12-03 09:29:45 25 4
gpt4 key购买 nike

我正在尝试在我的博客文章中添加 Facebook 分享按钮。所以我正在考虑以下链接:

https://developers.facebook.com/docs/plugins/share-button

当我将以下 JavaScript 代码放入我的网站模板中时,来自上面的链接:

<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count"></div>

当我将其保存在第 6 行时:

js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";

它给出以下错误:

"Error parsing XML: The reference to entity "version" must end with the ';' delimiter"

为什么会将此错误显示为“;”出现在上面一行的末尾???

提前致谢。

最佳答案

从此Source :

It looks like something is interpreting your document as XML rather than HTML. XML is much stricter than HTML - one of the rules is that ampersands (&) have a special meaning. They mean "here comes an XML entity", which is a special character. For instance, you can type " to insert ", or > to insert > into your document.

因此解决方案是将 src 中的 & 更改为 &

js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&amp;version=v2.4";

关于javascript - Facebook 分享社交插件的 javascript 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31553274/

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