问题
I've been trying for some time to create an image including the "like" icon but I'd like the icon to be "live", i.e when clicking on it the "like" action happens to that current page. I know how to use image map but I dont understand how link it to the "like" application. please help...
回答1:
You can't trigger the Like a page from your code, this is because the like button is running inside an iframe and therefore isn't accessible from your code.
The only Like action you can trigger yourself from code is "Like an object on Facebook", you find more about that in this question.
If you want an event to trigger on your page after a user have pressed an Like button you can do it by subscribing to the like event using the Facebook Javascript SDK.
You can find how to subscribe to an Like in the the documentation here:
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
回答2:
The Like button operates in an iframe and this will prevent you from doing what you're trying to do -
It's partially a clickjacking protection to prevent sites from triggering a 'Like' action using any interface other than the actual Like button in its own iframe
来源:https://stackoverflow.com/questions/8277449/how-to-trigger-facebook-like-from-an-image-map