2011-09-22 61 views
0

我正在寫一個Facebook應用程序,它使用badgeville向玩家提供點數。有時點需要授予頁面加載時,但我也有一些Facebook的社會插件,如評論框和喜歡的按鈕。看起來,因爲頁面正在等待這些加載它並不加載badgeville的東西,以允許授予點正確運行的功能。當Facebook完成加載後運行一個javascript函數

有沒有什麼事情可以用來運行功能,一旦Facebook完成這些事情? 我發現「FB.Canvas.setDoneLoading();」但我不知道如何實現它。

感謝

回答

0

當然,你可能有這樣的事情:

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

這將確保setDoneLoading()不叫,直到FB功能設置的初始化。

0

假設你在做服務器端登錄,你應該使用FB.Event.subscribe。如果您正在初始化狀態爲FB的對象:true,則auth.statusChangeauth.authResponseChange事件將在FB對象初始化後觸發。

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 
}); 
相關問題