Disqus

Load Disqus On Click

Posted by Weston Ganger on September 07, 2015

You can increase the load times on your pages by letting the user choose when to load Disqus comments. You can place this on a button or link or whatever


<div id="comments">
  <button id="show-comments" type="button">Show Comments</button>
  <div id="disqus_thread"></div>
</div>

$(function(){
  $('#show-comments').on('click', function(){
    var disqus_shortname = 'your_disqus_user_name';

    (function() {
      var disqus = document.createElement('script'); 
      disqus.type = 'text/javascript'; 
      disqus.async = true;
      disqus.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(disqus);
    })();

    $(this).hide(); // Hide the button
  });
});


Related External Links:


Posted in Javascript and Tagged with disqus javascript 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts