www.webdeveloper.com
Results 1 to 8 of 8

Thread: cssRules are null in Chrome

  1. #1
    Join Date
    Jun 2010
    Posts
    4

    cssRules are null in Chrome

    This is turning up null all of a sudden. I'm running version 5.0.375.70

    alert(document.styleSheets[0].cssRules);

    shows null in chrome with a very simple test page and single css file with just one rule, but turns up as an CSSRuleList for FF Safari, Opera etc...

    document.styleSheets[0].rules is also null in my Chrome browser. How do i get the css rules in chrome? I think this actually used to work in my older versions of chrome but now I'm second guessing myself.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654

  3. #3
    Join Date
    Jul 2007
    Posts
    386
    Have you tried Safari? Both browsers use Webkit as their engine so if it works or does not work on one it should happen on the other one too.

    According to Quirksmode, Safari supports both cssRules and rules.

  4. #4
    Join Date
    Jun 2010
    Posts
    4
    right, but this is my code, maybe there is a error.

    Code:
    <html>
    <head>
    <link rel='stylesheet' type='text/css' href='test.css'>
    <script type='text/javascript'>
    window.onload=function()
    {
    	alert(document.styleSheets[0].cssRules);
    }
    </script>
    </head>
    <body>
    </body>
    </html>

  5. #5
    Join Date
    Jun 2010
    Posts
    4
    yes, working safari, not chrome - strange i know.

    perhaps a file path error. I just have test.css in the same dir as my htm test file posted above.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Still no problem in Chrome

  7. #7
    Join Date
    Jun 2010
    Posts
    4
    odd, when i uploaded it to my webserver it worked. my server is unix, my pc is windows, so i tried changing it from href='test.css' to href='/test.css' and that fixed it locally

    problem solved... i = nub.

  8. #8
    Join Date
    Feb 2006
    Posts
    2,927
    Its a good bet that Ims is using the file: protocol to test his code.
    I usually work on a server, and have had no troubles with any of the Chromes and their styleSheets methods.

    When I opened a page from the file system Chrome was the only browser that would not expose some of the styleSheets rule sets, although it could find every styleSheet loaded.

    It seems to be a file permissions weirdness, though not even Safari 5 shares it.

    Test your code on a local server with http: instead of the file system. It's the only way to use IE without getting a migraine, but all the browsers are really built for http.
    Last edited by mrhoo; 06-12-2010 at 10:36 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles