2012-02-27 6 views
1

可能性の重複:
How to render a plugin added dynamically?Facebookのプラグインを更新するには?

これは私のcodeです:

HTML

<div id="fb-root"> 
<fb:like href="www.google.it" send="false" layout="button_count" width="auto" show_faces="true"></fb:like> 
<div id="newFB"></div> 
<a href="#" id="showFacebook">Add new "I Like" and refresh</a> 

jQueryの

function renderFB() { 
    (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); } (document, 'script', 'facebook-jssdk')); 
} 

renderFB(); 

$("#showFacebook").click(function() { 
    $('#newFB').html('<fb:like href="www.google.it" send="false" layout="button_count" width="auto" show_faces="true"></fb:like>'); 

    renderFB(); 
}); 

ページロード時にすべてのFBプラグインをロードします。その後、新しいプラグインを追加して再レンダリングします。または、可能であれば、最後に挿入されたもののみ。

可能ですか?そして私はそれをどうすればいいのですか?

答えて

2

だけではなく、XFBMLのIFRAMEを試してみてください。..のような

$('#newFB').html('<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.google.it&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>');

関連する問題