Why FB.XFBML.parse() doesnt render my plugin?

﹥>﹥吖頭↗ 提交于 2019-11-30 18:10:56

问题


My code :

<a id="render-me" href="javascript:void(0);">Render me</a>
<div id="social-facebook"></div>​

$('#render-me').click(function (e){
    e.preventDefault();

    $('#social-facebook').html("<fb:like id='button-facebook' href='http://www.google.com' send='false' layout='button_count' width='450' show_faces='false'></fb:like>");
    FB.XFBML.parse(document.getElementById('button-facebook'));    
});

I click, but the button is not rendered. Where am I wrong?


回答1:


You have to specify a node already in DOM. So, you can't use:

FB.XFBML.parse(document.getElementById('button-facebook'));

use instead:

FB.XFBML.parse(document.getElementById('social-facebook'));

and it will work fine ;)




回答2:


Try to add this markup

<div id="fb-root"></div>

in bottom of page and make sure you are added FB script. Please have a look the image

Please follow these steps you will able to solve you problem.

For more info please go through this link https://developers.facebook.com/docs/reference/plugins/like/



来源:https://stackoverflow.com/questions/12840786/why-fb-xfbml-parse-doesnt-render-my-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!