首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在加载Disqus后运行javascript

如何在加载Disqus后运行javascript
EN

Stack Overflow用户
提问于 2013-06-09 05:26:29
回答 5查看 1.4K关注 0票数 5

我正在尝试使用Disqus api,我需要运行一些javascript代码来修改Disqus注释线程。

如何在Disqus线程加载后运行javascript代码?

EN

回答 5

Stack Overflow用户

发布于 2014-02-21 00:03:05

我遇到了类似的问题。我能想到的唯一可行的解决方案是运行setInterval()来检查Disqus容器div的高度。

示例:

代码语言:javascript
复制
var editable = true; // set a flag
setInterval(function() {
// Initially Disqus renders this div with the height of 0px prior to the comments being loaded. So run a check to see if the comments have been loaded yet.
  var disqusHeight = $('#dsq-2').height();
  if ( disqusHeight > 0 ) {
    if (editable) { // To make sure that the changes you want to make only happen once check to see if the flag has been changed, if not run the changes and update the flag.
      editable = false;
      // Your code here...
    }
  }
}, 100);
票数 4
EN

Stack Overflow用户

发布于 2017-02-21 05:51:05

试试这个:

代码语言:javascript
复制
function disqus_config() {
  this.callbacks.onReady.push(function () {
    // your code
  });
}
票数 3
EN

Stack Overflow用户

发布于 2015-07-21 17:05:46

这是新版本Disqus的Brandon Morse的修改代码,当Disqus加载注释时脚本停止。

代码语言:javascript
复制
var interval = setInterval(function() {
    var $ = jQuery;
    var disqusHeight = $('#disqus_thread').height();
    if ( disqusHeight > 52 ) {  // height 52px is header of Disqus, more than 52px means that disqus load comments
      // Your code
        clearInterval(interval); // after loaded comment we stop this script
    }
}, 100);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17004009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档