facebook - "FB is undefined"IE8错误

标签 facebook internet-explorer internet-explorer-8

我在 Facebook 上创建了一个请求对话框,它在 Firefox 和 Chrome 中运行得很好,但在 IE8 中,它给了我错误:FB 未定义。请在下面找到我使用的代码。

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

最佳答案

您的问题是,当您尝试使用 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(); 
});

关于facebook - "FB is undefined"IE8错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8228276/

相关文章:

java - 使用最新版本的 Android 版 Facebook SDK 发布带有描述的图像

html - 部分和小标签的 css 在 IE 和 Chrome 中是不同的

internet-explorer - 如何防止SVG元素通过IE11中的标签获得焦点?

javascript - 是什么触发了 ie 中对象标签的 onerror 事件处理程序?

javascript - .split() 在 IE8 中无法正常工作

ios - 在 iOS 应用程序公开发布之前提交 Facebook 应用程序以供审核?

javascript - FB.login 无效的 redirect_uri (xd_proxy.php)

javascript - Joomla Gantry 框架 ie8 LESS/CSS

internet-explorer-8 - 关于边界半径的问题-IE8

facebook - 在 Facebook 上分享来自 "private"站点的内容时出现问题