与动态加载的内容整合Facebook像按钮 [英] integrate facebook like button with dynamically loaded content

查看:110
本文介绍了与动态加载的内容整合Facebook像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的网站包含的项目通过AJAX动态加载的清单。当你向下滚动页面,更多的项目被加载。

The website I am working on consists of a list of items dynamically loaded via AJAX. As you scroll down the page, more items are loaded.

现在我的客户希望增加一个类似Facebook的按钮(和谁的人喜欢这个数),以每这些项目。

Now my customer wants to add a Facebook like button (and the number of people who liked this) to each of these items.

集成像按钮默认是没有问题的,但我怎么等按钮添加到通过AJAX加载的项目?如果一个新的项目被加载,如何Facebook的API知道,有一个新的像的,它需要获取多少人喜欢这个计数DOM树按钮?

Integrating the default like button is no problem, but how do I add the like button to the items loaded via AJAX? If a new item is loaded, how does the Facebook API know that there is a new like button in the DOM tree for which it needs to fetch the count of how many people liked this?

先后在如何做到这一点的人的经历?有一个例子可以?我的搜索didnt发现任何有用的,除了集成的标准像按钮。

Has anyone experience in how to do this? Is there an example available? My search didnt turn up anything usefull except integrating the standard like button.

推荐答案

晚的答案,但你可以使用Facebook的API的解析函数的函数的回调加载新的元素来呈现新的类似按钮:

Late answer, but you could use the parse function of the Facebook API in a callback of your function that loads the new elements to render the new like buttons:

FB.XFBML.parse();

您也可以直接解析器要渲染的元素,所以它不会再呈现类似按钮已经存在的:

You can also direct the parser to the elements you want rendered, so it doesn't re-render the already existing like buttons:

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

这是直接从文档:<一href="https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/">https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

这篇关于与动态加载的内容整合Facebook像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆