问题描述
我正在构建一个应用程序,在主页面上加载一些产品,然后在加载后点击每个产品项目,它会显示小弹出窗口,并显示像特定产品的按钮和评论供稿,我写了这样的代码。
im building an application which loads some products on main page with search.also after click on each product item after load it'll show small popup and shows like button and comment feed for specific product i wrote a code like this.
function renderFBWidgets() {
window.fbAsyncInit = function () {
FB.init({ appId: '165987850132000', status: true, cookie: true, xfbml: true
});
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
var u = //get product url
$('.productlist').append('<div style="margin-left: 30px;"><fb:like href="' + u + '" send="true" layout="standard" width="430" show_faces="false" action="like" colorscheme="light"></fb:like></div>');
}
但每当我点击产品时facebook初始化所有脚本都有动态加载按钮的好方法?
but each time when i click on the product facebook initialized all script is there any good way to load like button dynamically?
谢谢
推荐答案
全部就像按钮在iframe中呈现一样。如果您使用XFBML方法,Facebook的all.js脚本会在页面上找到< fb:like>
标记,并为每个标记创建一个iframe。如果在脚本运行后添加< fb:like>
标记,则需要运行处理该标记并生成其iframe。
All Like Buttons are rendered in iframes. If you use the XFBML approach, Facebook's all.js script finds the <fb:like>
tags on the page and creates an iframe for each one. If you add an <fb:like>
tag after the script has run, you need to run FB.XFBML.parse to process that tag and generate its iframe.
另一种选择是将新的Like按钮附加为iframe。请务必取消选中中的发送按钮选项。但是,使用这种方法会丢失发送按钮,并且只能获得标准布局至少400px宽的评论。
Another option is to append the new Like Button as an iframe. Be sure to uncheck the Send Button option in Facebook's button generator. However, with this approach you lose the Send Button and you only get Comments with a standard layout at least 400px wide.
这篇关于如何动态加载facebook像按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!