style 数量判断的实现有问题
afc163 opened this issue · comments
afc163 commented
seajs-style/src/seajs-style.js
Line 33 in 75ef396
// IE
if (element.styleSheet) {
// http://support.microsoft.com/kb/262161
if (doc.getElementsByTagName('style').length > 31) {
throw new Error('Exceed the maximal count of style tags in IE')
}
element.styleSheet.cssText += cssText
}
// W3C
else {
element.appendChild(doc.createTextNode(cssText))
}
以上这段代码中,当 IE678 下 link css 和 style 的数量超过 31 个时,element.styleSheet
将直接变为 null,从而无法到达判断 style 数量的逻辑。
而且会进入 W3C 的逻辑中,导致运行时报错。
afc163 commented
- if (element.styleSheet) {
+ if (element.styleSheet !== undefined) {
afc163 commented
另外看这两个例子:
http://jsfiddle.net/5Zu3w/9/
http://jsfiddle.net/5Zu3w/14/
发现带有 rel="stylesheet"
的 link 同样也被计算在 style 的 31 数量限制内,而 type="text/css"
的 link 不在其列。