开发者

Change URL of Facebook like button with Ajax

开发者 https://www.devze.com 2023-01-24 17:43 出处:网络
I am wondering whether it is possible to change the action of a Facebook like button on an Ajax event.

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&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;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

0

精彩评论

暂无评论...
验证码 换一张
取 消