我正在从 Facebook 开发者网站上的 this page 复制代码,但 fbAsyncInit() 方法从未触发。我也读过 this page ,我用很多不同的方式调整了代码,但我无法触发该方法。你的意见?
此外,尽管如此,当我尝试运行此代码和 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', // 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>
最佳答案
我遇到了同样的问题。在异步加载之前,我似乎在其他地方加载了 JavaScript 库 //connect.facebook.net/en_US/all.js
。
这可能有点困惑。
我删除了过早加载标签定义,现在一切正常。
关于Javascript:我的 fbAsyncInit() 方法永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9184163/