Here is the code:
You'll notice the alert(document.styleSheets[x].cssRules.length)
fails with a "security exception". Any workaround for this. I am asking because there are a couple of "CSS lazy loading" classes out there that use this feature to detect if the CSS document is loaded.
Also: is the security exception a correct behavior/does it conform to standards?
You can get that error when trying to read a stylesheet loaded from a different domain or server, or trying to read an @import rule.
For your purpose, just check the document.styleSheets.length .
As of 2013, you can set the "crossorigin" attribute on the <link>-Element to signal the browser that this CSS is trusted (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link).
After that, you can access its rules via Javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With