Mathias Bader
Mathias Bader

Reputation: 3856

Javascript substr in Internet Explorer 8

I get an error when running the following code using Internet Explorer 8:

for (var lang_elem in this.langElems) {
    if (this.langElems.hasOwnProperty(lang_elem)) {  // ignore attributes down the prototype chain
        var www1 = this.langElems[lang_elem].length;
        var xxx1 = line.substr(0, www1);
        var yyy1 = this.langElems[lang_elem];

        if (xxx1 == yyy1) {
            elem_type = lang_elem;
            break;
        }
    }
}

The Debugger stops in the line where xx1 is defined (I obviously defined these three variables for debug purposes) with the following message:

Unterbrechung bei JScript-Laufzeitfehler - Das Objekt unterstütz diese Eigenschaft oder Methode nicht.

which translates into

Break at JScript-runtime error - The object doesn't support the attribute or method.

I checked, but as to my knowledge, IE8 should support the substr-method. I call it with line.substr(0,2), which should work (no negativ parameters).

Does anyone have an idea why this error is shown?

Upvotes: 0

Views: 1217

Answers (1)

Philip
Philip

Reputation: 779

Are you sure that line is a string at this point? That's normally the message that comes up when a variable is null or undefined. Try sticking a console.log(line); just before your call to substr. I also can't see it defined in your example but you might of just trimmed it out by mistake.

Upvotes: 1

Related Questions