How to detect when facebook's FB.init is complete

后端 未结 12 2264
我寻月下人不归
我寻月下人不归 2020-11-28 01:28

The old JS SDK had a function called FB.ensureInit. The new SDK does not seem to have such function... how can I ensure that I do not make api calls until it is fully initia

12条回答
  •  余生分开走
    2020-11-28 01:55

    Here is a solution in case you use jquery and Facebook Asynchronous Lazy Loading:

    // listen to an Event
    $(document).bind('fbInit',function(){
        console.log('fbInit complete; FB Object is Available');
    });
    
    // FB Async
    window.fbAsyncInit = function() {
        FB.init({appId: 'app_id', 
             status: true, 
             cookie: true,
             oauth:true,
             xfbml: true});
    
        $(document).trigger('fbInit'); // trigger event
    };
    

提交回复
热议问题