Firefox not able to enumerate document.styleSheets[].cssRules[]

后端 未结 7 1795
-上瘾入骨i
-上瘾入骨i 2020-12-16 15:33

Here is the code:

  • http://jsfiddle.net/salman/2hyYg/
  • http://jsfiddle.net/salman/2hyYg/show/

You\'ll notice the alert(document.styl

7条回答
  •  一个人的身影
    2020-12-16 16:35

    Try with condition: (IE workaround)

    function aftermath(index) {
        var css = document.styleSheets[index].rules || document.styleSheets[index].cssRules;
        alert(css.length);
    }
    

    This is giving the error:

    aftermath(document.styleSheets.length - 1);
    

    If i set it to 0 all work fine... The problem is that the css is not ready at this time, if you need to access it, you need to do that in a second moment

    Last edit:

    If you whant keep css updated from source, you can use a php proxy for loading it:

    
    

    Then you can get it using e.g. /proxy.php?version=1.7.0&theme=humanity

提交回复
热议问题