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

后端 未结 7 1777
-上瘾入骨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:

    <?php
    $name = 'http://ajax.googleapis.com/ajax/libs/jqueryui/$_GET[version]/themes/$_GET[theme]/jquery-ui.css';
    $fp = fopen($name, 'rb');
    fpassthru($fp);
    exit;
    ?>
    

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

    0 讨论(0)
提交回复
热议问题