-1

After an earlier question relating to this error.

Error: unable to get value of the property ‘split’: object is null or undefined

An answer was offered to add the following code:

/* Cross-Browser Split 1.0.1
(c) Steven Levithan <stevenlevithan.com>; MIT License
An ECMA-compliant, uniform cross-browser split method */

var cbSplit;

// avoid running twice, which would break `cbSplit._nativeSplit`'s reference to the native `split`
if (!cbSplit) {

cbSplit = function (str, separator, limit) {
    // if `separator` is not a regex, use the native `split`
    if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
        return cbSplit._nativeSplit.call(str, separator, limit);
    }

    var output = [],
        lastLastIndex = 0,
        flags = (separator.ignoreCase ? "i" : "") +
                (separator.multiline  ? "m" : "") +
                (separator.sticky     ? "y" : ""),
        separator = RegExp(separator.source, flags + "g"), // make `global` and avoid `lastIndex` issues by working with a copy
        separator2, match, lastIndex, lastLength;

    str = str + ""; // type conversion
    if (!cbSplit._compliantExecNpcg) {
        separator2 = RegExp("^" + separator.source + "$(?!\\s)", flags); // doesn't need /g or /y, but they don't hurt
    }

    /* behavior for `limit`: if it's...
    - `undefined`: no limit.
    - `NaN` or zero: return an empty array.
    - a positive number: use `Math.floor(limit)`.
    - a negative number: no limit.
    - other: type-convert, then use the above rules. */
    if (limit === undefined || +limit < 0) {
        limit = Infinity;
    } else {
        limit = Math.floor(+limit);
        if (!limit) {
            return [];
        }
    }

    while (match = separator.exec(str)) {
        lastIndex = match.index + match[0].length; // `separator.lastIndex` is not reliable cross-browser

        if (lastIndex > lastLastIndex) {
            output.push(str.slice(lastLastIndex, match.index));

            // fix browsers whose `exec` methods don't consistently return `undefined` for nonparticipating capturing groups
            if (!cbSplit._compliantExecNpcg && match.length > 1) {
                match[0].replace(separator2, function () {
                    for (var i = 1; i < arguments.length - 2; i++) {
                        if (arguments[i] === undefined) {
                            match[i] = undefined;
                        }
                    }
                });
            }

            if (match.length > 1 && match.index < str.length) {
                Array.prototype.push.apply(output, match.slice(1));
            }

            lastLength = match[0].length;
            lastLastIndex = lastIndex;

            if (output.length >= limit) {
                break;
            }
        }

        if (separator.lastIndex === match.index) {
            separator.lastIndex++; // avoid an infinite loop
        }
    }

    if (lastLastIndex === str.length) {
        if (lastLength || !separator.test("")) {
            output.push("");
        }
    } else {
        output.push(str.slice(lastLastIndex));
    }

    return output.length > limit ? output.slice(0, limit) : output;
};

cbSplit._compliantExecNpcg = /()??/.exec("")[1] === undefined; // NPCG: nonparticipating capturing group
cbSplit._nativeSplit = String.prototype.split;

} // end `if (!cbSplit)`

// for convenience...
String.prototype.split = function (separator, limit) {
    return cbSplit(this, separator, limit);
};

After trialling the code above and deleting caches it was found to do nothing...can anyone help at all, kind regards in advance.

Thanks EdoDodo for the above code but can you offer any further help as I am almost tearing my hair out and it did not work in the end, one point to note, the linked in button on the home page (if commented out) makes that site work for the home page and the error goes away but I really want the linked in buttons for each post excerpt on the home page.

site is:

www.mobileinquirer.com

  • Did you pass a regular expression into the split function as the separator. That appears to be what it's for. A sample of what didn't work for you would be more likely to get you an answer. – jfriend00 Jul 23 '11 at 20:52
  • Sorry for my ignorance I really do not know....could you elaborate on what you mean?....i am linking to the file: – user859165 Jul 23 '11 at 20:53
  • Why does this site not allow you to press return without sending the comment? And how come it stops you adding many characters after the initial question?...I am sorry but my code you asked for is too long...will try separating it up. – user859165 Jul 23 '11 at 20:56
  • First, you can add code samples to your original question, not to the comments. Comments are one paragraph only. Second, why are you using this code - what are you expecting it to do for you? Third, what specific error or problem are you having in what piece of code? – jfriend00 Jul 23 '11 at 20:59
  • The above code does not work for IE, commenting out the linked in button does allow IE to work though....cheers. – user859165 Jul 23 '11 at 20:59
  • The code was suggested due to teh error: Error: unable to get value of the property ‘split’: object is null or undefined http://blog.stevenlevithan.com/archives/cross-browser-split – user859165 Jul 23 '11 at 21:00
  • I have just noticed I can edit my original post thanks, not very user friendly though but cheers for letting me know. – user859165 Jul 23 '11 at 21:01
  • What is the "linked in button"? Please be more specific. http://www.mobileinquirer.com/ crashes IE9. – jfriend00 Jul 23 '11 at 21:06
  • Hi there it is a share button for each post on home page: seems to be the issue though but god knows why! – user859165 Jul 23 '11 at 21:10
  • what on earth is ` – Spudley Jul 23 '11 at 21:19
  • http://www.linkedin.com/publishers – user859165 Jul 23 '11 at 21:20

1 Answers1

2

Firefox shows me a script error on line 913 in this part of your script:

<script type="text/javascript">
    // <![CDATA[
        var disqus_shortname = 'mobileinquirer';
        var disqus_domain = 'disqus.com';
        (function () {
            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('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';
                }
            }
            var s = document.createElement('script'); s.async = true;
            s.type = 'text/javascript';
            s.src = 'http://' + disqus_domain + '/forums/' + disqus_shortname + '/count.js';
            (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
        }());
    //]]>
    </script>

The specific error is on this line:

url = nodes[i].parentNode.href.split('#', 1);

and it's because parentNode does not have an href. This error has nothing to do with the split function. The code is trying to obtain the value of the href attribute on the parentNode, but there is no href attribute so that resolves to undefined so the call to split fails. It has nothing to do with the split function. The issue is that your markup is apparently wrong and what I think is disqus code is expecting an tag around a tag, but it isn't finding that.

If you look at line 664-665 in the mobilinquirer.com HTML source, you will find this sequence at that line and then several times following:

<p><span
class="dsq-postid">8 Comments</span></p>

This code causes the error. The <span class="dsq-postid"> tag must have an <a href="xxx"> tag as it's parent or you will get this error. I see this same problem several problems in your HTML.

This problem has NOTHING to do with the split function. To make this error go away, you need to fix your HTML so that it is what the disqus code is expecting or remove the offending disqus code (which you don't seem to need) or both.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Many thanks I have been clearing up code for days.....your answer rings true though so will have to take a good look....one thing was deleting the disqus plugin did not resolve my matter at all for IE...so was still back to why it did not work......thanks for now and fingers crossed your right and I can solve it. – user859165 Jul 23 '11 at 21:24
  • Ok Disqus deleted completely and STILL the same issues now IE simply stops working and offers no debug........HEEEEEEELLLLLLLPPPPPP! – user859165 Jul 23 '11 at 21:51
  • The disqus code I referenced in my answer above is still there and is still causing the same error. Nothing has change with respect to the error I've reported on here. I would suggest you look at script errors in the Firefox or Chrome debuggers and work at learning how to track these issues down yourself. When Firefox and Chrome say your page is clear of errors, then try it in IE. – jfriend00 Jul 23 '11 at 22:33
  • Ok will do, not great at debugging javascript at all when it gets confusing...heads all over from hours upon hours of trying to sort....thanks for help will post back results if I sort fully – user859165 Jul 24 '11 at 00:07
  • Did fully delete Disqus though and the error was the same, simply turned back on as it did not solve. – user859165 Jul 24 '11 at 00:08
  • Not trying to sound clever here and I will not purport to being any good at javascript or php etc, but why doesn't deleting my disqus comments not solve the problem as I have tried on your basis if my issue is..."This problem has NOTHING to do with the split function. To make this error go away, you need to fix your HTML so that it is what the disqus code is expecting." – user859165 Jul 24 '11 at 00:17
  • Ok so deleted - nodes[i].parentNode.href = url + '#disqus_thread'; so it read: nodes[i].parentNode. '#disqus_thread'; for both areas that this is called, still nothing....will keep going. – user859165 Jul 24 '11 at 00:26
  • Also added anchors to this part: return ''.$comment_text.''; Nothing. – user859165 Jul 24 '11 at 00:29
  • The disqus error is still happening. You either need to remove the disqus code that is causing the error or fix the HTML. IE still crashes. You will have to either trace through the initialization code in a javascript debugger or disable large sections of the javascript code one at a time until you find which section is causing the crash. I have no idea what is causing it. There is an enormous amount of stuff in that page so it's probably best to remove things one at a time until it stops crashing to isolate what is causing the crash. – jfriend00 Jul 24 '11 at 01:09
  • This and other variations does nothing also:

    – user859165 Jul 24 '11 at 01:12
  • 1
    Please just remove the block of code that my answer starts with. That's disqus code and is what is causing the script error. I have no idea if that's the IE problem or not, but you need to fix this item first. StackOverflow is not meant for this kind of iterative discussion/troubleshooting. I will be leaving this issue now. – jfriend00 Jul 24 '11 at 01:19
  • Thank you to everyone who has tried to help....I shall bid you all farewell although unresolved. – user859165 Jul 24 '11 at 01:30
  • In the spirit of StackOverflow, the problem you asked about in your first question (the "split" problem) has actually been solved. The answer to that question is that you do not need this additional "split" code and you either need to fix your disqus HTML or remove the offending disqus code that is causing the "split" error or both. I know you have more work to make your page work in IE which is probably unrelated to that question. If when you get into that problem some more, you have specific questions about how to fix something you find, you can ask a new question about that. – jfriend00 Jul 24 '11 at 01:35
  • See that is what I thought I was doing in all honesty....but got slapped down for asking too many questions, altered as a result of answers that were not what I was after...seems quite the spirit in here I must say...no prisoners for sure...."A language-independent collaboratively edited question and answer site for programmers.".....think I might try elsewhere but thanks to all who have tried to help, but this site does not fit my style of questioning me thinks. – user859165 Jul 24 '11 at 01:44