2012-02-27 42 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

剛剛嘗試IFRAME而不是XFBML ..

一樣,

$('#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>');