Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery hook on Facebook embed post finished

Is there something I can bind a jQuery event to when is Facebook embed post is finished loading?

I need to trigger a masonry reload after all my Facebook posts are loaded, because they only have the right height after the content is loaded.

The closest I got was:

$(window).on('load', function () {
    $('iframe').on('load', function () {
        $container.masonry();
    });
});

But somehow the event is triggered sometimes before the content is loaded.

like image 259
Nealv Avatar asked Mar 13 '14 13:03

Nealv


2 Answers

If you invoke the XFBML parser directly (so use xfbml=0 instead of the normally embedded xfbml=1) you can include a callback:

window.fbAsyncInit = function() {
    FB.XFBML.parse(null, function() {
        console.log("parsing is complete!");
    });
};
like image 105
Scott Stafford Avatar answered Nov 15 '22 10:11

Scott Stafford


It occurred to me that there is another way, using the ready handler -

$(window).on('load', function () {
    $('iframe').ready(function () {
        $container.masonry();
    });
});
like image 41
Jay Blanchard Avatar answered Nov 15 '22 09:11

Jay Blanchard