Javascript

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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts