Search code examples
facebookdom-eventsfacebook-like

How to catch action from Facebook 'Like' button


Is there a way to catch event of clicking Facebook like button? I don't want to integrate my app with Facebook, just need to count clicks of 'Like'. Tried :

$('.fb_iframe_widget').click(function(){
    alert("clicked");
});

but without any luck. If there is no way of doing this will I be able to count likes of particular pages when synced with FB API ?


Solution

  • You must use the xfbml like button rather than the iframe button. After you switch that, do the following:

    FB.Event.subscribe('edge.create', function(response) {
      // user clicked like button!
    });
    

    The facebook event "edge.create" is called when a like button is clicked. I have no idea why it is named that, but that will do what you are looking for.