1

Facebook currently has event handlers for facebook events such as like / recommend. But this is available only for xfbml version of the code. Since facebook is no longer supporting fbml / xfbml (http://www.allfacebook.com/facebook-markup-language-support-ends-jan-1-2011-12) how do we listen to events on iframes? You cannot use javascript methods listening to ids onclick and etc, esp for iframes owned by facebook / twitter. Is there any other solution to this?

Thank you but,

Thanks. I am already using the new Javascript SDK. Scroll down for my code, but I am assuming that this works only for the "xfbml" version of code for facebook like button? does the same apply for iframes too? Assumption based on this text on http://developers.facebook.com/docs/reference/plugins/like/:

The XFBML (also available in HTML5-compliant markup) version is more versatile, but requires use of the JavaScript SDK. The XFBML dynamically re-sizes its height according to whether there are profile pictures to display, gives you the ability (through the Javascript library) to listen for like events so that you know in real time when a user clicks the Like button, and it always gives the user the ability to add an optional comment to the like. If users do add a comment, the story published back to Facebook is given more prominence.

window.fbAsyncInit = function() {

   FB.init ({
     appId      :  ,// App ID
     channelUrl : ,// Channel File
     status     : true, // check login status
     cookie     : true, // enable cookies to allow the server to access the session
     xfbml      : true  // parse XFBML

   });

    // Listen to click event 
       FB.Event.subscribe('edge.create', function(response) {
     // Do something, e.g. track the click on the "Like" button here
      $('#someDiv').show();

     });

 };

 // Load the SDK Asynchronously
(function() {
 var e = document.createElement('script');
 e.type = 'text/javascript';
 e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
 e.async = true;
 document.getElementById('fb-root').appendChild(e);
 }());
Leena Samuel
  • 67
  • 2
  • 12

1 Answers1

1

Yes, you can subscribe to events using the new Javascript SDK. See here: https://developers.facebook.com/docs/reference/javascript/ and https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

DMCS
  • 31,720
  • 14
  • 71
  • 104
  • in short.. those events only work for xfbml.. and if xfbml is not going to be supported, is there some other work around for iframes? – Leena Samuel Jan 09 '12 at 17:48
  • No, those event subscriptions work for FB.ui actions. Please read https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/. The only event on there that you can subscribe to for xfbml is xfbml.render, which is not applicable in your situation.\ – DMCS Jan 09 '12 at 18:13
  • tried the iframe "like" button code and tried to listen with the code posted up, and it doesn't capture the like event, but it does when I used the xfbml code. – Leena Samuel Jan 09 '12 at 21:08
  • Since the iframe code isn't dependent on the Framework being loaded in the hosting page, I would doubt that it would fire off any events to the javascript. Try using the HTML5 version if you don't want to use the xfbml one. FWIW, any of the three all will output the like content, so there's no harm in swithcing away from the raw iframe html code. – DMCS Jan 09 '12 at 21:31
  • thank you.. the html5 version works fine.. I was just trying to see if there was a work around for iframes too because they load much faster on the site and also does not interfere with other ajax popups in the site like the html5 and xfbml versions which make a call to load the iframes – Leena Samuel Jan 09 '12 at 21:48