0

html:

<div id="fb-root"></div>

js:

$(document).ready(function(){
    window.fbAsyncInit = function() {
        FB.init();

        FB.getLoginStatus(function(response){
            runFbInitCriticalCode(); 
            console.log(response);
        });
    };

    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/ru_RU/all.js#xfbml=1";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
});

コードの実行後、div は iframe やその他の facebook タグで満たされますが、空です。ページに何も表示されないのですが、何が問題なのですか?

4

2 に答える 2

1

facebook-jssdk指定されたコードのfb-rootjs ファイルの最後の 2 番目の行に置き換えます。

(document, 'script', 'fb-root'));
于 2013-04-15T11:37:31.197 に答える
0

このコードを試してください:

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
    if(typeof(FB) != 'undefined') {
        FB.init({
            appId: facebookAppId, xfbml: true, status: true, cookie: true, oauth: true
        });
    }
};
(function() {
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}());
</script>

私の場合facebookAppIdは、Facebook アプリケーション ID を持つ JavaScript 変数です。ここで作成する必要があります。この後でのみ、JS API を利用できます。

詳細はこちら

于 2013-04-15T05:21:11.083 に答える