Skip to content

IE Style elements don't work in Less.js #160

@schneidh

Description

@schneidh

I noticed that
<style type="text/less">...</style>
doesn't appear to be working in IE. It throws an exception when trying to set the innerHTML of the generated style element. I was able to implement a fix for this by changing:

function loadStyles() {
...
            new(less.Parser)().parse(styles[i].innerHTML || '', function (e, tree) {
                styles[i].type = 'text/css';
                styles[i].innerHTML = tree.toCSS();
            });
...
}

to:
function loadStyles() {
...
new(less.Parser)().parse(styles[i].innerHTML || '', function (e, tree) {
styles[i].type = 'text/css';
if (styles[i].styleSheet) { // IE
styles[i].styleSheet.cssText = tree.toCSS();
} else {
styles[i].innerHTML = tree.toCSS();
}
});
...
}

This seems to resolve the issue. I also noticed less was already doing this logic for link elements, so I believe this is the correct fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions