So I’m trying to do some event handling when a user clicks the like button.
My Facebook button is being created asynchronously via:
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
And that works great.
I have the following function running as well:
window.fbAsyncInit = function() {
FB.init({status: true, cookie: true, xfbml: true});
FB.Event.subscribe("xfbml.render", function() {
console.log('xfbml.render');
FB.Event.subscribe("edge.create", function(targetUrl) {
console.log('edge.create');
});
FB.Event.subscribe("edge.remove", function(targetUrl) {
console.log('edge.remove');
});
});
};
So far, when I load the page, I get ‘xfbml.render’ in the console. Then I click the like button & I get nothing.
I’d like for it to spit out the console message ‘edge.create’.
Does anyone have any idea what could cause this?
I’ve put this page on a publicly accessible site before (It’s currently on my dev rig) & it still didn’t work. I can again if requested.
In order to use XFBML on your webpage, you must add an XML namespace attribute to the root element of your page. Without this declaration, XFBML tags will not render in Internet Explorer.
Next,
You load the SDK using the standard element and calling (FB.init()). You must specify a element named fb-root within the document as well.
and then make sure you add your app id inside FB.init() function,
Here’s a full working code: