Search code examples
ajaxfacebookxfbml

Change URL of Facebook like button with Ajax


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 following 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.


Solution

  • 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