未捕获ReferenceError:FB未定义 [英] Uncaught ReferenceError: FB is not defined
问题描述
我使用这个代码:
打开html标签与
< html xmlns =http://www.w3.org/1999/xhtmlxmlns:fb =http://ogp.me/ns/fb#>
在开始标签后立即输入这个
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
// init FB JS SDK
FB.init({
appId:'MY_APP_ID',//应用程序信息中心的应用程序ID
status:true,//检查Facebook登录状态
xfbml:true //在页面上查找社交插件
});
//附加的初始化代码(如添加事件侦听器)在这里
};
//异步加载SDK
(function(){
//如果我们已经安装了SDK,我们完成
if(document。 getElementById('facebook-jssdk')){return;}
//获取第一个脚本元素,我们将用它来查找父节点
var firstScriptElement = document.getElementsByTagName( 'script')[0];
//创建一个新的脚本元素并设置其ID
var facebookJS = document.createElement('script');
facebookJS.id ='facebook-jssdk';
//将新脚本的源码设置为Facebook JS SDK的源码
facebookJS.src ='//connect.facebook.net/it_IT/all .js';
//将Facebook JS SDK插入DOM
firstScriptElement.parentNode.insertBefore(facebookJS,firstScriptElement);
}());
< / script>
最后,按钮
< fb:like href =http://mydomain.it/layout =button_countaction =likeshow_faces =falseshare =false>< / fb :像>
< script>
FB.Event.subscribe('edge.create',
function(href,widget){
alert('Ti piace'+ href);
});
< / script>
类似的工作,但不会打开警报,我在控制台中收到此错误。 >
未捕获ReferenceError:FB未定义
任何解决方案?
看到这个主题: FB未在Facebook登录中定义。
您正在尝试在按钮之后使用 FB
,但尚未定义:
< fb:like href =http://mydomain.it/layout =button_countaction =likeshow_faces =false share =false>< / fb:like>
< script>
FB.Event.subscribe(...
^ --- FB尚未定义!
将您的 window.fbAsyncInit
函数中的 FB.Event.subscribe
代码移动到其中有这个评论其他初始化代码
I know this question is asked frequently, but I have not found the solution. I use this code:
open the html tag with
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
in the index immediately after the opening tag I entered this
<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>
finally, the button
<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>
the like works, but does not open the alert and I got this error in console.
Uncaught ReferenceError: FB is not defined
Any solutions?
See this thread: FB is not defined in Facebook Login.
You are trying to use FB
right after your button, and it's not defined yet:
<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!
Move that FB.Event.subscribe
code inside your window.fbAsyncInit
function, where you have that comment "Additional initialization code"
这篇关于未捕获ReferenceError:FB未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!