I have the following code (which is the initialization of the facebook API),
I don’t understand why this snippet runs on-load without being called anywhere else in the code!
The funny thing is that when i remove the fbAsyncInit function “wrapper” it works the same!
so how does the FB.init is called without calling fbAsyncInit anywhere else?
window.fbAsyncInit = function() {
FB.init({appId: '00000000000000000', status: true, cookie: true, xfbml: true});
FB.getLoginStatus(function(response) {
if (response.session) {
console.log('User is logged in.');
FB.api("/me?fields=name,picture", handleMe);
}
else {
console.log('User is not logged in.');
window.location = "http://wall-et.com/index.php/test/login/";
}
});
};
For this to work, you need to include a script from Facebook (perhaps connect.facebook.net/en_US/all.js) in your page.
The script runs
window.fbAsyncInitfrom awindow.setTimeout(..., 0), causing your code to be run after the Facebook script has been completely loaded and initialized.