我试图在html页面上删除所有css规则。这个问题已经被问到elsewhere但是我没有找到像stackoverflow这样的网站的解决方案。如果您粘贴在控制台中:
for (var p in document.styleSheets) {
console.log(document.styleSheets[p])
}
您会注意到某些cssRules
为空(至少在Chrome中)。
CSSStyleSheet {ownerRule: null, cssRules: null, rules: null, type: "text/css", href: "http://cdn.sstatic.net/stackoverflow/all.css?v=284b207e2cf7"…}
CSSStyleSheet {ownerRule: null, cssRules: CSSRuleList, rules: CSSRuleList, type: "text/css", href: null…}
CSSStyleSheet {ownerRule: null, cssRules: CSSRuleList, rules: CSSRuleList, type: "text/css", href: "http://static.adzerk.net/Extensions/adFeedback.css"…}
CSSStyleSheet {ownerRule: null, cssRules: null, rules: null, type: "text/css", href: "http://cdn.sstatic.net/clc/styles/jobs.min.css?v=8228069a845b"…}3
然而,导航到http://cdn.sstatic.net/stackoverflow/all.css?v=284b207e2cf7只会产生缩小的css。
当document.styleSheets[].cssRules
对象为空时,有没有办法以编程方式获取网站的css规则?