使用 javascript 插入 fb:comments

发布于 2024-10-22 06:30:44 字数 481 浏览 8 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妖妓 2024-10-29 06:30:45

FB:Root 在构建时应该是页面的一部分,并使用 FB 提供的 Javascript 在文档加载时异步加载 Facebook JS 库......就像 FB 描述的那样。

插入 FB 注释

document.getElementById('theplace').innerHTML="<fb:comments blah blah blah></fb:comments>"

然后,使用和 THEN

FB.XFBML.parse(document.getElementById('theplace'));

。这段代码将初始化 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

document.getElementById('theplace').innerHTML="<fb:comments blah blah blah></fb:comments>"

and THEN

FB.XFBML.parse(document.getElementById('theplace'));

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

意中人 2024-10-29 06:30:45

我能够解决在 onLoad() 回调上调用 FB.XFBML.parse 的问题

I was able to solve the problem calling FB.XFBML.parse on an onLoad() callback

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文