1

A few days ago I've faced with a problem of getting cssRules data on a webpage.

document.styleSheets[i].cssRules

Works only for style tags and link tags with same domain style sheet path.

So, it's pretty hard to access these rules if I use style sheets from different domains,

Or if I browse html pages from local file system - it's impossible to access the rules even from local filesystem style sheet, and also web-located style sheet. in another words - it's impossible to get rules from any stylesheet from local fs html page.

and also it's impossible to get rules if i use data urls, for example:

<link rel="stylesheet" href="data:text/css;base64,Kntjb2xvcjpyZWQ7fQ==">

I do not know why this unfair behaviour appears, but i hope someday i'll realize true reasons of these restrictions.

Because I do not really understand why to prevent js access to css rules when the browser itself accesses and renders them without any problems (crossdomain, local filesystem, etc.)

any suggestions on how to access these rules anyway?

In my case i write an js extension that works on every web site (so I cannot simply move required css to my domain).

Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
exdee
  • 46
  • 5
  • possible duplicate of [Accessing Cross Domain Stylesheet with .cssRules](http://stackoverflow.com/questions/3211536/accessing-cross-domain-stylesheet-with-cssrules) – Dr.Molle Jun 24 '12 at 16:05
  • May be it would help someone with same as mine situation. As i said i make js extension (for Chrome), and if create link node on **Background** with required url (of any domain) - it's possible to get stylesheet's rules (as with normal same-origin stylesheet) with **Background** page's JS env. So it's possible to pass through request href of link tag to Background page, and get response with styles back. Of course extension should have permissions to access those domains – exdee Jun 25 '12 at 05:05

0 Answers0