我正在尝试在bootstrap 2标签集中使用Facebook Comments小部件。如果放置注释的选项卡不是“默认”或显示的选项卡,则FB注释iFrame不会出现在选项卡上。
看到这个小提琴:http://jsfiddle.net/e9QkE/1/
(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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
有没有办法刷新标签或触发选项卡上的FB iframe?
答案 0 :(得分:0)
如果您的容器为display:none
,则不会显示Facebook注释,这是非默认选项卡的情况。
我使用的另一种方法是在显示容器之前不呈现fb注释。这可以通过使用
来实现window.fbAsyncInit = function () {
FB.init({
xfbml:false // Will stop the fb like button from rendering automatically
});
};
然后要渲染fb注释,可以使用
FB.XFBML.parse(); // This will render all tags on the page
//or the following is a Jquery example on how to render all XFBML within an element
FB.XFBML.parse($('#profile')[0]); // profile is the id of element which contains the fb code
// In plain js,
FB.XFBML.parse(document.getElementById("profile"));
参考: 来自SO答案的代码。