样式表规则 Return 仅在 iphone 上为空?
Stylesheets Rules Return Null only on iphone?
我试图通过 JavaScript 阅读样式表规则,但同时 document.styleSheets[0].rules
和 document.styleSheets[0].cssRules
return Null
。
澄清:
如果加载的 css 看起来像这样:
.example{
position: relative;
height: 100%;
width: 100%;
overflow-x: hidden;
}
使用 Javascript,如果我调用 document.styleSheets[0].rules 假设 css 是 html 文件中的第一个,我应该得到规则数据。但这并没有发生。
此问题仅发生在 iOS。它在 Safari 上运行良好,在 Android.
上也运行良好
谢谢。
所以我解决了这个问题。它似乎是由多种原因共同造成的。因为这是我第一次将我的代码与 cordova iOS 一起使用,所以我认为我在第一次添加 cordova-plugin-wkwebview-file-xhr 插件时没有正确修复 WkWebview 的 XHR 已知问题。我认为它没有正确添加。所以我不得不删除 iOS 平台,然后重新开始。我再次添加 cordova-plugin-wkwebview-file-xhr 并确保我有:
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
在配置文件中,样式规则按应有的方式显示。
我试图通过 JavaScript 阅读样式表规则,但同时 document.styleSheets[0].rules
和 document.styleSheets[0].cssRules
return Null
。
澄清:
如果加载的 css 看起来像这样:
.example{
position: relative;
height: 100%;
width: 100%;
overflow-x: hidden;
}
使用 Javascript,如果我调用 document.styleSheets[0].rules 假设 css 是 html 文件中的第一个,我应该得到规则数据。但这并没有发生。
此问题仅发生在 iOS。它在 Safari 上运行良好,在 Android.
上也运行良好谢谢。
所以我解决了这个问题。它似乎是由多种原因共同造成的。因为这是我第一次将我的代码与 cordova iOS 一起使用,所以我认为我在第一次添加 cordova-plugin-wkwebview-file-xhr 插件时没有正确修复 WkWebview 的 XHR 已知问题。我认为它没有正确添加。所以我不得不删除 iOS 平台,然后重新开始。我再次添加 cordova-plugin-wkwebview-file-xhr 并确保我有:
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
在配置文件中,样式规则按应有的方式显示。