fbAsyncInit在动态内容中不起作用

时间:2013-08-14 10:35:59

标签: javascript facebook jquery facebook-javascript-sdk

我有这个代码(来自FB开发者doc)

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
        appId: 'xxxxxxxxx',
        channelUrl: 'xxxxxxx',
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });

    FB.Event.subscribe('auth.authResponseChange',function(response) {
        if (response.status === 'connected') {
            FB.api('/me', function(response) {
                console.log('Good to see you, ' + response.name + '.');
            });
        } else if (response.status === 'not_authorized') {
            //FB.login();
        } else {
        }
    });
};

// Load the SDK asynchronously
(function(d) {
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {
        return;
    }
    js = d.createElement('script');
    js.id = id;
    js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));
</script>

上面的代码在index.html中,我通过ajax调用动态加载index.html。

我面临的问题是动态加载index.html时不会触发fbAsyncInit

任何想法如何解决这个问题?

0 个答案:

没有答案