Uncaught TypeError: Cannot read property 'split' of undefined
-
I am using Disqus plugin with WP Touch Pro and I’m seeing the following JavaScript error:
Uncaught TypeError: Cannot read property ‘split’ of undefinedThis is because the SPAN element is not a direct child of the A element; there is a DIV in between for styling. I changed the code printed by Disqus to handle this. Is there any chance you could include it in the next release?
var nodes = document.getElementsByTagName('span'); 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('data-dsqidentifier')); // mkrcho, 08/06/2015: added fix for cases when the span is not a direct child of the hyperlink var parentElm = nodes[i]; do { parentElm = parentElm.parentNode; } while (parentElm.tagName != 'A' && parentElm.parentNode); if (parentElm.tagName !== 'A') { continue; } url = parentElm.href.split('#', 1); if (url.length == 1) { url = url[0]; } else { url = url[1]; } nodes[i].parentNode.href = url + '#disqus_thread'; } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Uncaught TypeError: Cannot read property 'split' of undefined’ is closed to new replies.