Facebook fbAsyncInit 触发两次
我使用 Facebook 的 Javascript SDK 来允许登录/注销,我的问题是,当我使用他们的 window.fbAsyncInit 调用来启动 FB 会话时,它总是触发两次。我提供了一个简化的代码示例。我将不胜感激任何帮助!
在下面的代码中,“2”警报触发一次,然后“1”警报触发两次。
<html><head>
<script type="text/javascript">
...some of my own functions, not related to Facebook...
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo FACEBOOK_APPID; ?>',
session : <?php echo json_encode($session); ?>, status:false, cookie:true, xfbml: true
});
alert("1");
FB.getLoginStatus(function(response) {
if(response.session) { ...do stuff... } else { ...do other stuff...}
});
};
alert("2");
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
...page contents...
</body></html>
I'm using Facebook's Javascript SDK to allow login/logout, and my problem is that when I use their window.fbAsyncInit call to initiate the FB session, it always fires twice. I've included a simplified code sample. I'd appreciate any help!
In the code below, the "2" alert fires a single time, and then the "1" alert fires twice.
<html><head>
<script type="text/javascript">
...some of my own functions, not related to Facebook...
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo FACEBOOK_APPID; ?>',
session : <?php echo json_encode($session); ?>, status:false, cookie:true, xfbml: true
});
alert("1");
FB.getLoginStatus(function(response) {
if(response.session) { ...do stuff... } else { ...do other stuff...}
});
};
alert("2");
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
...page contents...
</body></html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会不小心包含两个不同的 Facebook javascript。
You might accidentally be including two different Facebook javascripts.