Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run javascript after Disqus loaded

I am trying to work with Disqus api and I need to run some javascript code that modify Disqus comments thread.

How to run the javascript code after Disqus thread has loaded?

like image 510
qwerty Avatar asked Jun 08 '13 21:06

qwerty


2 Answers

I ran into a similar issue. The only working solution I was able to come up with was to run setInterval() to check the height of the Disqus container div.

Example:

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);
like image 169
morsecodemedia Avatar answered Oct 04 '22 19:10

morsecodemedia


Try this:

function disqus_config() {
  this.callbacks.onReady.push(function () {
    // your code
  });
}
like image 31
Abram Avatar answered Oct 04 '22 20:10

Abram