javascriptjqueryfacebookloaded

Get Facebook likebox height after SDK loaded


Is there a way to get the correct facebook likebox height after the stream is loaded?

I'm trying this way, it won't work.

window.fbAsyncInit = function() {
  FB.init({
    appId      : 'xxx', 
    status     : true,
    cookie     : true,
    oauth      : true,
    xfbml      : true

  });

  FB.Event.subscribe('auth.login', function(response) {
    window.location.reload();
  });
  console.log($('.fb_iframe_widget').height());
};

In the console i see null.

It means the fbAsyncInit runs before the whole stream is loaded and there is no fb_iframe_widget element or I don't get it.

If i wait for pageload and type in the console

console.log($('.fb_iframe_widget').height());

It goes good, I get the height of the loaded Facebook box.

Thank you for the help.


Solution

  • I have found the answer here https://stackoverflow.com/a/19295464/2930036

    The correct way to do this is

    FB.Event.subscribe("xfbml.render", function () {
      console.log($('.fb-page').height());
    });