Cog

Disqus On AJAX Or Turbolinks Site

Posted by Weston Ganger on March 22, 2015

On an AJAX or Turbolinks site with disqus you need to do some extra checking to see if it needs to be reset or instantiated.


<div id="disqus_thread"></div>
<script type="text/javascript">
  if(typeof DISQUS === "undefined"){
    var disqus_shortname = 'your_shortname'; // required: replace example with your forum shortname

    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = "//" + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
  }else{
    DISQUS.reset({
      reload: true,
      config: function () {
        this.page.identifier = document.title;
        this.page.url = location.href;
      }
    });
  }
</script>

**Credits to Yos Riady for this solutions


Related External Links:


Posted in Web Development and Tagged with turbolinks ajax disqus 


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