I am wondering whether it is possible to change the action of a Facebook like button on an Ajax event.
What I am trying to do: I display an article when the page was loaded. At the end of the article I have a button which loads the next article via Ajax. Additional I have the followi开发者_JS百科ng Facebook like button:
<fb:like href="http://www.myurl.com" layout="standard" show-faces="true" action="like" id="fblike" />
When I load the next article I put the new URL of the article into the "href"-attribute via Javascript (which works fine), but when I click on the like button the initial article url will be pushed to facebook, and not the new one.
Any ideas?
Thanks a lot.
You don't actually need the iframe version as it is more limited and not as good for performance. All you need to do is use this snippet to re-render the button in the DOM; without a page refresh, the element does not "refresh" otherwise:
FB.XFBML.parse();
See docs here: http://developers.facebook.com/docs/reference/javascript/
You could try the iFrame version instead the XFBML version:
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>
See here for more infos:
http://developers.facebook.com/docs/reference/plugins/like
精彩评论