我正在尝试使用Disqus api,我需要运行一些javascript代码来修改Disqus注释线程。
如何在Disqus线程加载后运行javascript代码?
发布于 2014-02-21 00:03:05
我遇到了类似的问题。我能想到的唯一可行的解决方案是运行setInterval()来检查Disqus容器div的高度。
示例:
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);发布于 2017-02-21 05:51:05
试试这个:
function disqus_config() {
this.callbacks.onReady.push(function () {
// your code
});
}发布于 2015-07-21 17:05:46
这是新版本Disqus的Brandon Morse的修改代码,当Disqus加载注释时脚本停止。
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);https://stackoverflow.com/questions/17004009
复制相似问题