Tuesday, May 28, 2013

Dynamic change facebook like button href


12down voteaccepted
It works for me for XFBML tag as well without using FB iframe and even works with multiple FB like calls for AJAX
You just need to wrap the entire XFBML code in JS/jQuery and parse it as shown below:
$('#like').html('<fb:like href="' + url + '" layout="button_count" show_faces="false" width="65" action="like" font="segoe ui" colorscheme="light" />');
if (typeof FB !== 'undefined') {
    FB.XFBML.parse(document.getElementById('like'));
}
HTML code:
<span id="like"></span>
Surly this is going to be helpful for more guys :)

No comments:

Post a Comment