andrewb andrewb - 6 months ago 57
jQuery Question

Detect when Facebook like button is clicked

I have the following JavaScript code

<div class="fb-like-box" data-href="snip" data-colorscheme="light"
data-show-faces="false" data-header="false" data-stream="false"
data-show-border="true"></div>


I am trying to detect when the like button is clicked. The above code renders an iframe so my jquery event handler of

$('.fb-like-box > button').on('click', function() { console.log('Clicked'); });


Never fires. I tried wrapping this div and other content in a wrapper div and target that in the $() call but it only fires when the other content is clicked, not the area that is rendered by the Facebook SDK.

Answer Source

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.3

You just need to subscribe to the edge.create event for likes. See docs for example code.

But as commented, you are not allowed to reward users for liking. Read the platform policy for more information: https://developers.facebook.com/policy/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download