How to execute a script after the user clicks the Like button on Facebook Like?

I am trying to use the Facebook Like button through an iFrame, for example:

<iframe id="test" src="http://www.facebook.com/plugins/like.php? href=http://yoururl.com/&amp; layout=button_count&amp; show_faces=false&amp; width=50&amp; action=like&amp; colorscheme=light&amp; height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:21px;" allowTransparency="true"> 

After the user first clicks the Like button, I want to execute Javascript in my DOM content. How can i do this?

+4
source share
1 answer

Do you want some Javascript to be executed when you like something?

You can use the Javascript SDK for Facebook for this, especially the edge.create event.
Cm

This should also work with the IFrame version. If not, you need to switch to the XFBML-Like button. It definitely works with the XFBML version.

Example:

 <!-- Load the SDK (or even better, load it asynchronously. See first link above --> <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> // initalize your Facebook App FB.init({ appId : 'YOUR APP ID', status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); // subscribe to the event FB.Event.subscribe('edge.create', function(response) { alert('you liked this'); }); FB.Event.subscribe('edge.remove', function(response) { alert('you unliked this'); }); </script> <!-- The XFBML Like Button, if the iframe version doesn't work (not 100% sure) <fb:like></fb:like> --> 
+5
source

All Articles