Disqus On AJAX Or Turbolinks Site

Posted by Weston Ganger

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:

Article Topic:Software Development - Web Development

Date:March 22, 2015

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected