Howto add a callback after Facebook Comments loads

540 views Asked by At

I need to execute javascript code after the facebook comments plugin is properly rendered on the page (basically I need to get the #content's height)

Comments placement somewhere in the content:

<div id="content">
    <fb:comments href="http://domain.com/somelink.php" num_posts="25" width="728"></fb:comments>
</div>

Facebook init at the bottom of the page:

<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=<?=MY_FACEBOOK_APP_ID?>&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

I tried this:

FB.Event.subscribe("xfbml.render", function(response) {
    console.log($('#content').height());
});

...but got this error:

Uncaught ReferenceError: FB is not defined

Any ideas? Thanks!

0

There are 0 answers