问题描述
我正在将代码复制到Facebook的开发人员网站和fbAsyncInit()方法从不触发。我还阅读了,我已经调整了代码的几种不同的方式,我无法得到该方法的火。你的想法?另外,为什么值得,当我尝试运行这个代码和Chrome(在Mac上)并运行Firebug Lite时,我会收到一个错误,说Firebug Lite不能载入本页
这是代码...
< HTML>
< head>
< / head>
< body>
< div id =fb-root>< / div>
< script type =text / javascript>
window.fbAsyncInit = function(){
FB.init({
appId:'1234567890',// App ID
channelUrl:'//localhost/test.html' ,//通道文件
状态:true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true //解析XFBML
});
alert(此语句从不被调用);
};
//异步加载SDK
(function(d){
var js,id ='facebook-jssdk'; if(d.getElementById(id)){return ;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src =//connect.facebook.net/en_US/all。 js;
d.getElementsByTagName('head')[0] .appendChild(js);
}(document));
< / script>
< / script>
< / body>
< / html>
我也有同样的问题。在异步加载之前,似乎我在其他地方加载了JavaScript库 // connect.facebook.net/en_US/all.js
。
这可能让我感到困惑。
我删除了过早的加载标签定义,现在我没事了。
I'm copying the code right out of this page on Facebook's developer website and the fbAsyncInit() method never fires. I've also read this page, I've tweaked the code quite a few different ways, and I cannot get the method to fire. Your thoughts?
Also, for what it's worth, when I try and run this code and Chrome (on Mac) and run Firebug lite, I get an error that says "Firebug Lite cannot be loaded in this page"
Here's the code...
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '1234567890', // App ID
channelUrl : '//localhost/test.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
alert("this statement never gets called either");
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</script>
</body>
</html>
I had the same problem. It seemed I loaded the JavaScript library //connect.facebook.net/en_US/all.js
in some other place before the async loading.
That probably confused things a bit.
I removed the premature load tag definition and now I am fine.
这篇关于Javascript:我的fbAsyncInit()方法永远不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!