gpt4 book ai didi

facebook - "FB is undefined"IE8错误

转载 作者:行者123 更新时间:2023-12-02 19:25:53 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com