Reputation: 31
I have created a request dialog on Facebook, and it works very good in Firefox and Chrome, but in IE8, it gives me the error: FB is undefined
. Kindly find below the code I used.
<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>
Upvotes: 3
Views: 4230
Reputation: 35
I faced this same issue SPECIFICALLY when using ie8.
Quick fix can possibly be achieved via NOT using HTTP://connect.facebook.net/en_US/all.js
and instead using HTTPS://connect.facebook.net/en_US/all.js
For some reason going SSL solves the problem.
Upvotes: 0
Reputation: 1660
Your problem is that the Facebook features have not finished loading by the time you are trying to use them. According to 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.
Their documentation is pretty good (not 100% complete) and would be useful to you. For now, it should be enough to wrap your code like this:
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();
});
Upvotes: 1