Skip to content

Instantly share code, notes, and snippets.

@GCheung55
Forked from jiggliemon/FB.init.detector.js
Created October 25, 2011 19:26
Show Gist options
  • Save GCheung55/1313938 to your computer and use it in GitHub Desktop.
Save GCheung55/1313938 to your computer and use it in GitHub Desktop.
Facebook Init detector!
$(document).bind('FB.ready',function(){
console.log('FB is ready');
FB.api('/me',function(response){
console.log(response);
});
});
var _FB = {
count: 0
,interval : setInterval(function(){
try{
if(FB._session && (typeof FB._session !== 'undefined')){
clearInterval(_FB.interval);
$(document).trigger('FB.ready');
}
} catch(e){
if(_FB.count++ > 100) {
clearInterval(_FB.interval);
throw new Error('`FB` hasn\'t become available.');
}
}
},15)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment