IE9 throws a DOM exception: INVALID_CHARACTER_ERR (5)

In the script below, IE9 throws an error:

SCRIPT5022: DOM exception: INVALID_CHARACTER_ERR (5) mootools-1.2.1-core-yc.js, line 118 character 1

Document.implement({
    newElement: function (A, B) {
        if (Browser.Engine.trident && B) {
            ["name", "type", "checked"].each(function (C) {
                if (!B[C]) {
                    return;
                }
                A += " " + C + '="' + B[C] + '"';
                if (C != "checked") {
                    delete B[C];
                }
            });
            A = "<" + A + ">";
        }
        return $.element(this.createElement(A)).set(B); //THIS IS LINE 118
    },
    newTextNode: function (A) {
        return this.createTextNode(A);
    },
    getDocument: function () {
        return this;
    },
    getWindow: function () {
        return this.window;
    }
});

This snippet is part of the Mootools js library that the developer used on the site. Is there a workaround for IE error?

+5
source share
1 answer

Yes, this code is garbage, you should never do such browser checks, it was taught in JavaScript 101 ... lol can't believe what in mootools? blech anyways

IE9 will no longer allow a crazy syntax document.createElement('<div style="background:red">yay!</div>');(no one has ever used it in the first place ...)

here is an example:

var d = document;
var x = d.createElement('div');

x.innerHTML = 'yay';
x.style.backgroundColor = 'red';
x.style.padding = '6px';
x.style.margin = '20px';

d.body.appendChild(x);

var sameHTML = '<div style="background:green;padding:6px;margin:20px;">yay!</div>';

// fails in IE > 8 and other browsers
try {
  var y = d.createElement(sameHTML);
  d.body.appendChild(y);
} catch (err) {
  d.body.appendChild(d.createTextNode(err)); 
}

// quick fix using innerHTML:
var temp = d.createElement('div');
temp.innerHTML = sameHTML;
d.body.appendChild(temp.childNodes[0]);

, , .innerHTML, mootools IE > 8, , mootools Browser.Engine.version - ...

edit: , , : Browser.Engine.trident , gyst , , ...

! : [] :

1.2.5 1.3. MooTools IE9.

script , , ... : http://mootools.net/download, 1.2.5 , ...

-ck

+9

All Articles