It is well known to do front-end development are eager to kick ie developers a few feet, ie developer reputation of the difference is not less than GFW developers, ignorant of the conscience of the market, everyone has to punish, but in China where the market share, there is no way can only bow to the reality.
Recently our products need to dynamically load a CSS in the browser, the previous code is directly used:
Copy Code code as follows:
var bubblecss = document.createelement (' style ');
Bubblecss.type = ' text/css ';
bubblecss.innerhtml = Blc_conf.bubblestyle;
document.getElementsByTagName (' head ') [0].appendchild (BUBBLECSS);
But this only IE9 support, under the IE8 will be a problem, has not noticed this piece, until the recent refactoring to do a complete test when the discovery.
Search on the Internet a skill, tried, workable, but there are some problems
Copy Code code as follows:
Window.bc_bubble_css = Blc_conf.bubblestyle;
Document.createstylesheet ("Javascript:bc_bubble_css");
Here you can create a style defined by the variable bc_bubble_css, but because HTML5 is becoming popular, we also have some CSS3 selector in our CSS, and using this method will cause IE8 parser to parse to CSS3 Selector the time to throw the exception and stop parsing subsequent CSS, which makes the CSS only half loaded, online search methods are used stylesheet type of addrule to increase, but this need to specify their own CSS2 selector and style,
So you need to take a single rule from the CSS and then call addrule in turn, example:
Copy Code code as follows:
var s = document.createstylesheet ();
var rules = Blc_conf.bubbleStyle.replace (/\/\*[^\*]*\*\//g, ""). Replace (/@[^{]*\{/g, '). Match (/[^\{\}]+\{[^\}]+\}/ g);
for (var i = 0; i < rules.length; i++) {
var m = Rules[i].match (/(. *) \s*\{\s* (. *) \}/);
if (m) {
try {
S.addrule (M[1], m[2]);
catch (e) {
}
}
}
There are two replacements at the beginning, which remove the gaze and part of the CSS3 selector, but there are still selector that need to be caught in the back try catch.
Again despise the person who designs IE interface