Sfwd favicon 152

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 


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