首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何检测facebook的FB.init何时完成

如何检测facebook的FB.init何时完成
EN

Stack Overflow用户
提问于 2010-08-23 22:27:57
回答 9查看 123.9K关注 0票数 119

旧的JS SDK有一个名为FB.ensureInit的函数。新的SDK似乎没有这样的功能……如何确保在api完全启动之前不进行api调用?

我在每个页面的顶部都包含了这样的内容:

代码语言:javascript
运行
复制
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php echo $conf['fb']['appid']; ?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Canvas.setAutoResize();
  };

  (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>
EN

Stack Overflow用户

发布于 2015-06-18 21:43:02

有时fbAsyncInit不能工作。我不知道为什么,然后使用这个变通方法:

代码语言:javascript
运行
复制
 var interval = window.setInterval(function(){
    if(typeof FB != 'undefined'){
        FB.init({
            appId      : 'your ID',
            cookie     : true,  // enable cookies to allow the server to access// the session
            xfbml      : true,  // parse social plugins on this page
            version    : 'v2.3' // use version 2.3
        });

        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });
        clearInterval(interval);
    }
},100);
票数 1
EN
查看全部 9 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3548493

复制
相关文章

相似问题

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