gpt4 book ai didi

javascript - Uncaught ReferenceError : FB is not defined

转载 作者:IT王子 更新时间:2023-10-28 23:53:37 26 4
gpt4 key购买 nike

我知道这个问题经常被问到,但我还没有找到解决办法。我使用此代码:

打开html标签
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">

在我输入的开始标签之后的索引中

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'MY_APP_ID', // App ID from the app dashboard
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});

// Additional initialization code such as adding Event Listeners goes here
};

// Load the SDK asynchronously
(function(){
// If we've already installed the SDK, we're done
if (document.getElementById('facebook-jssdk')) {return;}

// Get the first script element, which we'll use to find the parent node
var firstScriptElement = document.getElementsByTagName('script')[0];

// Create a new script element and set its id
var facebookJS = document.createElement('script');
facebookJS.id = 'facebook-jssdk';

// Set the new script's source to the source of the Facebook JS SDK
facebookJS.src = '//connect.facebook.net/it_IT/all.js';

// Insert the Facebook JS SDK into the DOM
firstScriptElement.parentNode.insertBefore(facebookJS, firstScriptElement);
}());
</script>

最后是按钮

<fb:like href="http://mydomain.it/" layout="button_count" action="like" show_faces="false" share="false"></fb:like>
<script>
FB.Event.subscribe('edge.create',
function(href, widget) {
alert('Ti piace ' + href);
});
</script>

类似的作品,但没有打开警报,我在控制台中收到了这个错误。

Uncaught ReferenceError: FB is not defined

有什么解决办法吗?

最佳答案

查看此主题:FB is not defined in Facebook Login .

您正尝试在按钮之后使用 FB,但尚未定义:

<fb:like href="http://mydomain.it/" layout="button_count" action="like" show_faces="false" share="false"></fb:like>
<script>
FB.Event.subscribe(...
^--- FB isn't defined yet!

FB.Event.subscribe 代码移到 window.fbAsyncInit 函数中,其中您有注释“附加初始化代码”

关于javascript - Uncaught ReferenceError : FB is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400457/

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