Yes that would be easier but I don't want to load the Facebook
javascript everytime, only when it is needed.
I think the issue happened because the FB object was called before the
script was loaded.
So I added some code to wait until the code is loaded:
private native void initFacebook(String fbAppId) /*-{
var fbroot = $doc.createElement('div');
fbroot.setAttribute('id', 'fb-root')
$doc.body.appendChild(fbroot);
var script = $doc.createElement("script");
script.src = "http://connect.facebook.net/en_US/all.js";
script.type = "text/javascript";
$doc.body.appendChild(script);
function callback() {
$wnd.FB.init({
appId : fbAppId,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true
// parse XFBML
});
$wnd.FB.login(function(response) {
if (response.session) {
$wnd.Alert("Logged in");
} else {
$wnd.Alert("Cancelled");
}
});
}
if (script.readyState) { //IE
script.onreadystatechange = function() {
if (script.readyState == "loaded"
|| script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
}-*/;
I guess I need to add some timeout management here, and cleanup as well ...
If anyone has other advise I would be happy to hear it.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.