• 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://ww.wp.xz.cn/plugins/disqus-comment-system/

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