15

is there a callback function (e.g. onComplete) for this? I would like to display a loader.

FB.XFBML.parse()
fabian
  • 5,433
  • 10
  • 61
  • 92

3 Answers3

26

Yes, the second parameter is the callback function. For example this should work:

FB.XFBML.parse(document.getElementById('some_element'), function() {
    alert('I rendered');
});
jhchen
  • 14,355
  • 14
  • 63
  • 91
  • 1
    Yep, it's also described in the [documentation](https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse) – czerasz Jun 05 '14 at 12:43
8

To parse the whole page by the same time

FB.XFBML.parse(document, function(){
    alert('I rendered');
});
Remy Mellet
  • 1,675
  • 20
  • 23
1

As of 2013 this does not work. Google Chrome will have "blinking" like buttons until it is finally rendered for me. This event is called before rendering is done.

To test this I try to hide the container before which has the like buttons (this works fine). Then I test to show the container in the function() { }); of the FB.XFBML.parse, that's when it looks like the newly loaded buttons are blinking.

Only having this issue in google chrome, but it proves that it's not after all like buttons have finished rendering in google chrome atleast.

Pragnesh Chauhan
  • 8,363
  • 9
  • 42
  • 53
Elrinth
  • 51
  • 3
  • I can well appreciate you might be having rendering problems (and Facebook doesn't exactly have the best API documentation), but for what it's worth the callback function *itself* does fire for me in the manner I'd expect. (My situation is a blog with infinite scroll where I'm adding a comments iframe after each post is loaded and it does seem to be triggered correctly each time it's added to the DOM). – William Turrell Apr 28 '14 at 20:34