最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Reload the comment count of Disqus - Stack Overflow

programmeradmin1浏览0评论

I am loading articles with AJAX. When I want to show their comment counts I use:

DISQUSWIDGETS.getCount();

This works. But when I load more articles and call the function again it does not show the comment counts of the articles. It also does not give any error. Is there a way to solve this problem in Javascript?

I am loading articles with AJAX. When I want to show their comment counts I use:

DISQUSWIDGETS.getCount();

This works. But when I load more articles and call the function again it does not show the comment counts of the articles. It also does not give any error. Is there a way to solve this problem in Javascript?

Share Improve this question edited Jan 24, 2014 at 12:52 user170442 asked Jan 24, 2014 at 12:49 KlaasvaakKlaasvaak 5,64416 gold badges48 silver badges68 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 19

It might be something of a hack, but this works:

# Undefine disquswidgets to force a refresh also on ajax reload
window.DISQUSWIDGETS = undefined;
$.getScript("http://" + disqus_shortname + ".disqus.com/count.js");

Basically you trick Disqus into believing that the typeof is undefined, which will make it execute the same code again as it does the first time it's run.

You should use this:

DISQUSWIDGETS.getCount({reset: true});

For more information, see here

This was the error that annoys my console for a couple of months console error here for reference

Basically, you shouldn't run the getCount function whenever the DISQUSWIDGETS variable is undefined.

// call the count js first
<script async='async' id='dsq-count-scr' src='//yourwebsite.disqus.com/count.js' type='text/javascript'/>

<script type='text/javascript'>
// then the solution to reload disqus comment count safely
if(typeof DISQUSWIDGETS != "undefined") {                                                                                                                    
    DISQUSWIDGETS.getCount({ reset: true });
}
</script>

I have also faced this issue and for the solution I found some good resources and solution from them.

For more enter link description here.This one works for me.

 window.DISQUSWIDGETS.getCount({ reset: true });
发布评论

评论列表(0)

  1. 暂无评论