我想为从某人的新闻提要的 facebook fql 流中检索到的每个帖子添加一个类似 facebook 的按钮。所以href是动态的,一直在变化,我尝试了3种方法来实现这个;
(1) 当我在 html 文件中包含以下内容时,它只会显示“喜欢”按钮,但它与该特定帖子无关。显然,href 是空的。
<div class="fb-like" data-href="" data-send="false" data-width="250" data-show-faces="true"></div>
(2) 我在 html 中包含了以下 div
<div id=fblikebutton></div>
和 JavaScript:
fblikebutton_markup += '<div class="fb-like" data-href="'+post_href+'" data-send="false" data-width="250" data-show-faces="true"></div>';
$('#fblikebutton').empty().append(fblikebutton_markup);
post_href 是当前帖子的 href,我正在检索正确的 href。但上面没有显示任何内容。
(3)以下代码会出现此错误:
Blocked a frame with origin "https://www.facebook.com" from accessing a frame with origin "http://static.ak.facebook.com". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
html:
<div id ="fblikebutton"></div>
Javascript:
fblikebutton_markup= '<fb:like href="'+post_href+'" send="false" width="250" show_faces="true"></fb:like>'
$('#fblikebutton').append(fblikebutton_markup);
FB.XFBML.parse(document.getElementById('fblikebutton'));
请帮忙!我查看了堆栈溢出,但没有任何帮助。
我现在进行了第四次尝试,仍然出现协议(protocol)必须匹配错误:
(4) jQuery("#fblikeblock").html(''); FB.XFBML.parse(document.getElementById('fblikeblock'));
现在有了第四种方法,按钮消失了!它不起作用。:(
最佳答案
将类似 fb 的内容附加到容器(例如 $('.container')
后,运行 FB.XFBML.parse($('.container')[ 0])
或 FB.XFBML.parse($('.container'))
。
我已经在我之前做过的一个项目中实现了它。
已编辑:还要确保在调用 javascript FB.XFBML.parse 之前,页面中包含 FB js。
关于javascript - 如何集成 facebook like 按钮以获取动态内容 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17505028/