If I call a Facebook SDK function directly from an onclick from an anchor tag it works, but if I trigger it through jQuery’s $(document).ready(), it stops after first alert and does not throw any errors.
function lfr() {
alert('test if loaded'); /* This works in both calls. */
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
/* Do something - this only works through anchor tag onclick call. */
}
});
}
You should wire in your event handlers inside of the window.fbAsyncInit() function so the Facebook JavaScript SDK has had a chance to fully initialize.
So at the comment section Facebook’s documentation generally shows
// Additional initialization code hereyou should place your event handler hook up code.See: https://developers.facebook.com/docs/reference/javascript/ for more information.
FWIW, window.fbAsyncInit and the
$(document).ready()are not the same event nor do they occur at the same time.