插入fb:注释与javascript [英] Inserting fb:comments with javascript
问题描述
如何使用javascript插入Facebook评论插件?我的网站是ajax驱动,我需要加载/重新加载Facebook的评论插件取决于哈希(index.html /#首页) - >(index.html /#movie1)。我的第一个想法是使用innerHTML:
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>";
然而,这不行,所以我尝试创建元素,然后附加它们,但是那里是< fb:comments>
元素,这是一个问题。
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.
最好的问候,
Ulrik
Best regards, Ulrik
推荐答案
FB:根目录应该是构建页面的一部分,并使用FB提供的Javascript异步加载文件加载的Facebook JS库....就像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.
然后,使用
document.getElementById('theplace').innerHTML="<fb:comments blah blah blah></fb:comments>"
和THEN
FB.XFBML.parse(document.getElementById('theplace'));
该位代码将初始化FB:注释。
This bit of code will initialise the FB:Comments.
您可以在我的网页上看到一个在跟踪视觉 - 比赛页面
我花了一段时间出汗这个代码,但现在全部功能了! FB文件令人震惊!
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!
最好的
这篇关于插入fb:注释与javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!