使用 javascript 插入 fb:comments
如何使用 JavaScript 插入 Facebook 评论插件?我的网站是 ajax 驱动的,我需要根据哈希值加载/重新加载 facebook 评论插件 (index.html/#frontpage) -> (index.html/#movie1)。我的第一个想法是使用innerHTML:
document.getElementById('facebook').innerHTML = "<div id='fb-root'></div><fb:comments href='http://viljegse.dk/' num_posts='10' width='572'></fb:comments></div>";
但这不起作用,所以我尝试创建元素然后附加它们,但是出现了
元素,这是一个问题。
此致, 乌尔里克
How do I insert the facebook comment plugin using javascript? My website is ajax-driven and I need to load/reload the facebook comment plugin depending on a hash (index.html/#frontpage) -> (index.html/#movie1). My first thought was to use innerHTML:
document.getElementById('facebook').innerHTML = "<div id='fb-root'></div><fb:comments href='http://viljegse.dk/' num_posts='10' width='572'></fb:comments></div>";
This however doesn't work, so I tried creating the elements and then appending them, but then there is the <fb:comments>
element, which is a problem.
Best regards,
Ulrik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FB:Root 在构建时应该是页面的一部分,并使用 FB 提供的 Javascript 在文档加载时异步加载 Facebook JS 库......就像 FB 描述的那样。
插入 FB 注释
然后,使用和 THEN
。这段代码将初始化 FB:Comments。
您可以在我的页面 Track Vision - 比赛页面 上看到此操作的示例
我在这段代码上花了一段时间,但现在它已经可以正常工作了! FB文档令人震惊!
一切顺利
FB:Root should be a part of the page at build time, and use the Javascript provided by FB to asynchronously load Facebook JS libraries on document load....just like FB describe.
Then, insert the FB comments using
and THEN
This bit of code will initialise the FB:Comments.
You can see a working example of this on my page at Track Vision - races page
I spent a while sweating on this code, but it's all functional now! FB documentation is shocking!
All the best
我能够解决在 onLoad() 回调上调用 FB.XFBML.parse 的问题
I was able to solve the problem calling FB.XFBML.parse on an onLoad() callback