Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get all stylesheets (including UA sheets)?

41 views
Skip to first unread message

Mike Ratcliffe

unread,
Mar 12, 2012, 8:31:04 AM3/12/12
to
Do we not have a way to list all stylesheets (including UA sheets)
used by a document? I could use domUtils.getCSSStyleRules() on every
element on the page, iterate the rules and gather the stylesheets that
way, but that seems like an awful hack.

I am sure that there is something obvious but my Monday brain just
ain't finding it :o/

Dao

unread,
Mar 12, 2012, 8:43:13 AM3/12/12
to
On 12.03.2012 13:31, Mike Ratcliffe wrote:
> I could use domUtils.getCSSStyleRules() on every
> element on the page, iterate the rules and gather the stylesheets that
> way

Well, no, a style sheet could target elements that aren't currently in
the page, or elements with some certain state.

> I am sure that there is something obvious but my Monday brain just
> ain't finding it :o/

You can hard-code the list, since you know the engine you're working
with (Gecko).

Mike Ratcliffe

unread,
Mar 12, 2012, 8:52:48 AM3/12/12
to
Hardcoding UA sheets could work, but then we could be listing sheets
that will never be used on a page. You make a good point about
selectors though.

Gijs Kruitbosch

unread,
Mar 12, 2012, 9:03:35 AM3/12/12
to Mike Ratcliffe
(disclaimer: very unfamiliar with layout, but this was a fun excuse to poke
around MXR)

You mean in JS or an external component? Because it seems you can ask
nsStylesheetService, but not nsIStylesheetService. In other words, if you're
inside layout, you could directly ask the component, but it isn't exposing that
info via its IDL, as far as I can tell, and it looks like UA ones aren't
included in document.styleSheets. Perhaps nsIStylesheetService could be made to
include this? I don't see a reason not to expose it (and many reasons why it may
be useful).

Cheers,
Gijs

sabine.micha...@gmail.com

unread,
Mar 12, 2012, 9:38:40 AM3/12/12
to Mike Ratcliffe
How did I miss that? Thanks ... https://bugzilla.mozilla.org/show_bug.cgi?id=734861.

Axel Grude

unread,
Mar 12, 2012, 3:50:21 PM3/12/12
to
here is what I do to find my style sheet in xul. Dunno if that helps you for content:

getMyStyleSheet: function() {
var styleSheetList = document.styleSheets;
for (var i=0; i<document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if (ss.title == "MyStyleSheet") {
return ss;
}
}
return 0;
},


hth,
Axel

sabine.micha...@gmail.com

unread,
Mar 12, 2012, 7:13:55 PM3/12/12
to
Unfortunately, this would not return UA stylesheets.
0 new messages