【问题标题】:Uncaught DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet'未捕获的 DOMException:无法从“CSSStyleSheet”读取“cssRules”属性
【发布时间】:2018-03-30 06:59:53
【问题描述】:

我在我的网站上看到以下错误,它似乎与跨域支持有关,但无法解决。谁能建议我如何解决这个问题?

错误:

Uncaught DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at addRule 

【问题讨论】:

标签: javascript cross-domain


【解决方案1】:

如果其他人遇到与跨域资源共享 (CORS) 政策相关的问题,请在此处讨论:https://github.com/Modernizr/Modernizr/issues/2296

您必须使用本地主机进行测试: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server

这是“try/catch”方法的解决方法:

try {
  var classes = stylesheets[s].rules || stylesheets[s].cssRules;
} catch (e) {
  console.warn("Can't read the css rules of: " + stylesheets[s].href, e);
  continue
}

遇到了这个问题,我绞尽脑汁,这似乎奏效了……祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 2017-07-08
    • 2018-07-23
    • 1970-01-01
    • 2021-06-09
    相关资源
    最近更新 更多