jquery脚本来监控disqus评论添加?
我想编写一个小脚本来监视页面上添加的 disqus 评论,并在添加新评论时触发一些通知回调。
对我来说,最简单的方法是定期监视 #dsq-comments div 的内容,并在其 html 内容发生变化时触发回调。
虽然这会起作用,但我想知道是否有更清洁的方法?
编辑:按照@Pekka的建议,我在我的 页面,效果非常好。这是我将 Disqus 集成到我的 网站 时最关心的问题之一,现在我有了一个可行的解决方案。
function disqus_config() {
this.callbacks.onNewComment = [function() {
$.get("/notifications/newcomment?...", function(data) {
});
}];
}
I would like to write a small script to monitor the disqus comments added on a page and fire some notification callbacks whenever new comments are added.
The simplest way for me to do it would be to periodically monitor the contents of the #dsq-comments div and trigger the callback whenever its html content changes.
While this will work, i'am wondering if there are any cleaner methods out there ?.
Edit : As suggested by @Pekka i implemented the onNewComment callback on my page and it works beautifully. This was one of my major concerns about integrating Disqus to my site and now i have a workable solution.
function disqus_config() {
this.callbacks.onNewComment = [function() {
$.get("/notifications/newcomment?...", function(data) {
});
}];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎有一个
onNewComment
回调。请参阅如何在我自己的分析工具中捕获 Disqus 评论活动?这篇博文在记录方面做得很好。
There seems to be an
onNewComment
callback. See How can I capture Disqus commenting activity in my own analytics tool?This blog post does a good job at documenting it.
Disqus 评论活动可以通过回调捕获,使用:
您将用您自己的函数替换 trackComment();。
下面是一个使用 JavaScript 动态加载 Disqus 评论的示例,您可以在其中找到添加新评论时将触发的 discus_config 函数。
Disqus commenting activity can be captured via callbacks, by using:
Where you will replace trackComment(); by your own function.
Here is an example that loads Disqus comments dynamically using JavaScript, where you can find the discus_config function that will be fired when a new comment is added.