2011-11-22 136 views
3

我在Facebook上創建了一個請求對話框,它在Firefox和Chrome中非常好用,但在IE8中,它給了我錯誤:FB is undefined。請在以下代碼中找到我使用的代碼。「FB is undefined」IE8的錯誤

<html xmlns=="http://www.w3.org/1999/xhtml" 
    xmlns:fb="https://www.facebook.com/2008/fbml"> 
    <head> 
    <title>Request Tester C</title> 

     </head> 

    <body> 
<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 

<p> 
</p> 
<script> 

    FB.init({ 
    appId : 'XXXXXXXXXXXXXXXXXXXXX', 
    status : true, 
    cookie : true, 
    oauth: true 
    }); 


    function sendRequestViaMultiFriendSelector() { 
    FB.ui({method: 'apprequests', 
     message: 'My Great Request' 
    }, requestCallback); 
    } 

    function requestCallback(response) { 
    // Handle callback here 
      window.location.href = "test.php"; 

    } 
      sendRequestViaMultiFriendSelector();  
    </script> 


</body> 
</html> 

回答

1

您的問題是Facebook功能在您嘗試使用它們時尚未完成加載。根據Facebook:

Almost all Facebook Connect's JS APIs are loaded asynchronously after calling FB.init(). Because of the asynchrous nature, the JS APIs are not necessaryly available immediately after making these calls. You should use FB.ensureInit or FB.Bootstrap.requireFeatures to ensure the JS APIs are loaded before using them.

We have a wiki documentation that describes this in more detail. However, we just found out that some Connect apps were calling Connect JS API such as FB.Connect.* and FB.Facebook.* immedidately after calling FB.init. This approach would cause intermittent failures because the functions may not be loaded yet.

他們的文件是相當不錯的(不是100%完成),並會對你有用。現在,它應該是足夠的包裹你這樣的代碼:

function sendRequestViaMultiFriendSelector() { 
    FB.ui({method: 'apprequests', 
    message: 'My Great Request' 
    }, requestCallback); 
} 

function requestCallback(response) { 
    // Handle callback here 
    window.location.href = "test.php"; 
} 

FB_RequireFeatures(["Connect"], function() { 
    FB.init({ 
    appId : 'XXXXXXXXXXXXXXXXXXXXX', 
    status : true, 
    cookie : true, 
    oauth: true 
    }); 
    sendRequestViaMultiFriendSelector(); 
}); 
+0

感謝安德魯的幫助,我用上面的代碼,但我得到了以下錯誤: 錯誤:FB_RequireFeatures沒有定義 源文件:XXXXXXXXXXXXXXXX 線:23個 任何想法,請 – user1022745

+0

你可能使用廣告攔截軟件的某種? –

0

我使用IE8時面臨同樣的問題具體。

快速修復可以通過可能不使用HTTP://connect.facebook.net/en_US/all.js ,而是使用HTTPS://connect.facebook.net/en_US/all.js

出於某種原因打算SSL解決問題來實現。