The problem is that the page is loaded before the Facebook API is ready. And if the user click on the Facebook connect button, the variable FB is not defined.
At the moment, I load Facebook API on document.ready.
I found a workaround with triggering a custom event.
Is it a good solution to load Facebook API in mobileinit event ? It will load before all others scripts and only once ?
Code :
$(document).on("mobileinit", function(){
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/all.js', function(){
window.fbAsyncInit = function() {
FB.init({
appId: 'appid',
channelUrl: 'channel.html',
//status: true,
cookie: true,
xfbml: true
});
$(document).trigger("facebook:ready");
}
});
});
Thanks for your answers