xiaofuzi / rollup-plugin-less

a less rollup plugin
22 stars 24 forks source link

In Ie8 will has some problem. #29

Open FiShelly opened 4 years ago

FiShelly commented 4 years ago

MDS tell us: The innerHTML property is read-only on the col, colGroup, frameSet, html, head, style, table, tBody, tFoot, tHead, title, and tr objects.

so:

The insertStyle function will get error in Ie8. By the way, document.head in Ie8 will get undefined.

solve:

function insertStyle (css) {
    if (!css) return;

    if (typeof (window) == 'undefined') return;

    var style = document.createElement('style');

    if ('styleSheet' in style) {  // to compatible IE8
        style = document.createElement('div');
        style.innerHTML = 'x<style>'+css+'</style>';
        style = style.lastChild;
    } else {
        style.innerHTML = css;
    }
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(style);
    return css;
}