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-jssdkfb-rootjs 文件中给定代码的倒数第二行。

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

Try this code:

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

In my case facebookAppId is a JavaScript variable with your Facebook application id. You need to create one here. Only after this you can take advantage on their JS API.

More info here.

于 2013-04-15T05:21:11.083 回答