2011-07-02 74 views
0

在我的页面的顶部,我把这个:Facebook连接JavaScript错误

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script> 

然后在身体我这样做:

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

然后我在网页中有这样以后:

<fb:login-button perms="publish_stream">Connect with Facebook</fb:login-button> 

然后我JQuery的文件准备好我有这样的:

FB.init({ 
     appId: '115************', cookie: true, 
     status: true, xfbml: true 
    }); 

在FF中,一切正常,当我点击连接Facebook时,一切正常。在所有其他的浏览器,一切都加载罚款,但是当我点击与Facebook连接,我得到这个错误:

FB.login() called before calling FB.init().

任何想法?

P.S.将init()脚本放在文档的head中也不起作用。给出同样的错误。

P.P.S.将init()移动到<head>现在可用于IE和FF,但不适用于Safari或Chrome。

回答

0

需要考虑的一件事是<div id="fb-root"></div>应始终是页面上的最后一件事,就在关闭</body>标记之前。

更新

此外,而不是在你的document.ready调用FB.init(),做什么Facebook documentation建议,并把它放在fbAsyncInit块:

<div id="fb-root"></div> 
<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 
    }); 
    }; 

    (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> 
+0

移动了它的好措施,但仍然没有解决问题= / – slandau