首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Facebook完成加载时运行javascript函数

在Facebook完成加载时运行javascript函数
EN

Stack Overflow用户
提问于 2011-09-22 22:31:40
回答 2查看 1.1K关注 0票数 0

我正在写一个facebook应用程序,它使用badgeville向玩家奖励积分。有时积分需要奖励时,页面加载,但我也有一些facebook的页面上像一个评论框和喜欢按钮的社交插件。看起来,因为页面正在等待这些内容的加载,所以它没有及时加载badgeville内容,以允许奖励积分的函数正确运行。

有没有什么事件可以用来在facebook完成它的工作后运行函数?我找到了"FB.Canvas.setDoneLoading();“,但不确定如何实现它。

谢谢

EN

回答 2

Stack Overflow用户

发布于 2011-09-25 07:21:15

当然,你可能会有这样的东西:

代码语言:javascript
复制
<script>
window.fbAsyncInit = function() {
FB.init({
  appId  : 'YOUR APP ID',
  status : true, // check login status
  cookie : true, // enable cookies to allow the server to access the session
  xfbml  : true,  // parse XFBML
  channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
  oauth : true //enables OAuth 2.0
});
FB.Canvas.setDoneLoading(
 function () {
  alert("Done loading");
 });
};
(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>

这将确保在设置和初始化FB函数之前不会调用setDoneLoading()。

票数 0
EN

Stack Overflow用户

发布于 2013-01-06 01:52:17

假设您正在进行服务器端登录,则应使用FB.Event.subscribe。如果你用状态: true初始化FB对象,那么auth.statusChangeauth.authResponseChange事件将在FB对象初始化后触发。

代码语言:javascript
复制
FB.Event.subscribe('auth.statusChange', function(response) {
    if(response.status == 'connected') {
        runFbInitCriticalCode();
    }
});

FB.init({
    appId  : 'appId',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7516524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档