[Project_owners] Extracting external Style Sheet definitions from DOM

Ingo Rau ingorau at imail.de
Tue Dec 7 23:52:43 EST 2004


On Tue, 7.December  2004 21:12, Matthew Wilson wrote:
> Ingo Rau wrote:
> > Hello!
> >
> > My extension needs to extract some style sheet definitions from a
> > webpage. If the webpage has
> > <BODY style="background-image:url(file);">
> > I can use obj.style.backgroundImage in JavaScript, no problem.
> >
> > But if I have
> > <BODY id="some_style">
> > and an external CSS file with for example
> > #some_style { background-image:url(file); }
> > only obj.style.id is defined.
> >
> > Of course, this makes sense, but I how do I get the CSS definition?
>
> I imagine it's all in here:
> http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html
I tried getComputedStyle() now, but it doesn't work:

  .html:
  <BODY id="bg-image">

  .css:
  #bg-image {background-image:url(file);}

  .js:
  var style=getComputedStyle(obj,null);
  alert(style.getPropertyValue("background-image"));

...always returns an empty string. Even with "embedded styles" (<BODY 
style="background-image:url(file);">).

I also tried
  alert(style.backgroundImage);
This works for embedded styles, but not for external files (didn't try 
<STYLE>...</STYLE>, probably doesn't work as well).
But the background image _is_ displayed - so where does Mozilla store that 
fact? Also tried it with other properties, same(=no) result...

Hope this isn't too confusing, it's probably because I'm confused ;)
Perhaps I could do my own kinda "getComputedStyle()", I just need to get the 
CSS definition for an id...

> > And is
> > there a difference between id and class?
> All the difference in the world. An id uniquely identifies an element
> within a document. A class can be applied to many elements.
Yeah, I knew - I was referring to the way they are accessed - but obviously 
that wouldn't matter if getComputedStyle worked the way it should...
-- 
Ingo Rau <ingorau at imail.de>
Siegen, Germany
ICQ: 7128634


More information about the Project_owners mailing list