Title: Javascript error triggered by some templates
Last modified: August 21, 2016

---

# Javascript error triggered by some templates

 *  [jonathanio](https://wordpress.org/support/users/jonathanio/)
 * (@jonathanio)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/javascript-error-triggered-by-some-templates/)
 * There’s an assumption in the JavaScript within the disqus.php file wherebythe
   _parentNode_ of a _span_ element which contains a _dsq-postid_ attribute will
   be an _anchor_. If attempts to call the _href_ attribute even though it may not
   exist and therefore breaks the code on the site.
 * The following patch fixes this issue:
 *     ```
       --- disqus.orig 2014-06-23 21:44:52.000000000 +0100
       +++ disqus.php  2014-06-23 21:48:58.000000000 +0100
       @@ -1181,10 +1181,12 @@
                    for (var i = 0, url; i < nodes.length; i++) {
                        if (nodes[i].className.indexOf('dsq-postid') != -1) {
                            nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
       -                    url = nodes[i].parentNode.href.split('#', 1);
       -                    if (url.length == 1) { url = url[0]; }
       -                    else { url = url[1]; }
       -                    nodes[i].parentNode.href = url + '#disqus_thread';
       +                    if (nodes[i].parentNode.href) {
       +                        url = nodes[i].parentNode.href.split('#', 1);
       +                        if (url.length == 1) { url = url[0]; }
       +                        else { url = url[1]; }
       +                        nodes[i].parentNode.href = url + '#disqus_thread';
       +                    }
                        }
                    }
                    var s = document.createElement('script'); s.async = true;
       @@ -1210,10 +1212,12 @@
                    for (var i = 0, url; i < nodes.length; i++) {
                        if (nodes[i].className.indexOf('dsq-postid') != -1) {
                            nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
       -                    url = nodes[i].parentNode.href.split('#', 1);
       -                    if (url.length == 1) url = url[0];
       -                    else url = url[1]
       -                    nodes[i].parentNode.href = url + '#disqus_thread';
       +                    if (nodes[i].parentNode.href) {
       +                        url = nodes[i].parentNode.href.split('#', 1);
       +                        if (url.length == 1) url = url[0];
       +                        else url = url[1]
       +                        nodes[i].parentNode.href = url + '#disqus_thread';
       +                    }
                        }
                    }
                    var s = document.createElement('script'); s.async = true;
       ```
   
 * [https://wordpress.org/plugins/disqus-comment-system/](https://wordpress.org/plugins/disqus-comment-system/)

The topic ‘Javascript error triggered by some templates’ is closed to new replies.

 * ![](https://ps.w.org/disqus-comment-system/assets/icon.svg?rev=1636350)
 * [Disqus Comment System](https://wordpress.org/plugins/disqus-comment-system/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/disqus-comment-system/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/disqus-comment-system/)
 * [Active Topics](https://wordpress.org/support/plugin/disqus-comment-system/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/disqus-comment-system/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/disqus-comment-system/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [jonathanio](https://wordpress.org/support/users/jonathanio/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/javascript-error-triggered-by-some-templates/)
 * Status: not resolved