小编Bra*_*nan的帖子

无法从Chrome 64中的本地css文件访问cssRules

这是一个简单的问题示例:

<html>
<head>
<link rel='stylesheet' href='myStyle.css'>
<script>
window.onload=function(){
    try{
        alert(document.styleSheets[0]); // works
        alert(document.styleSheets[0].cssRules); // doesn't even print undefined
    }catch(e){alert(e)} // catch and alert the error
}
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

myStyle.css body{background-color:green;}

如果你使用脚本工作正常 <style></style>

解决方案:
1,作品文件时在线/本地主机
2.作品与其他浏览器(如IE浏览器,微软边缘,火狐)
3 铬--allow-文件访问从-文件

html javascript css google-chrome cors

17
推荐指数
1
解决办法
2万
查看次数

未捕获的DOMException:无法从'CSSStyleSheet'读取'rules'属性

在Code.org的App Lab编辑器中,我们最近开始在Chrome 64中看到此错误:

Uncaught DOMException: Failed to read the 'rules' property from 'CSSStyleSheet'
Run Code Online (Sandbox Code Playgroud)

此函数中引发错误,旨在检测浏览器是否正在使用CSS媒体查询styleSheets[i].cssRules.

/**
 * IE9 throws an exception when trying to access the media field of a stylesheet
 */
export function browserSupportsCssMedia() {
  var styleSheets = document.styleSheets;
  for (var i = 0; i < styleSheets.length; i++) {
    var rules = styleSheets[i].cssRules || styleSheets[i].rules;
    try {
      if (rules.length > 0) {
        // see if we can access media
        rules[0].media;
      }
    } catch (e) {
      return false;
    } …
Run Code Online (Sandbox Code Playgroud)

javascript css google-chrome cors cssom

3
推荐指数
1
解决办法
4442
查看次数

标签 统计

cors ×2

css ×2

google-chrome ×2

javascript ×2

cssom ×1

html ×1