Can I fetch the value of a non-standard CSS property via Javascript?

前端 未结 6 654
傲寒
傲寒 2020-11-28 12:11

I am trying to read a custom (non-standard) CSS property, set in a stylesheet (not the inline style attribute) and get its value. Take this CSS for example:

         


        
6条回答
  •  遥遥无期
    2020-11-28 13:01

    I too have some pages that work wonderfully in MSIE, but have lots of info in styles and style sheets. So I'm thinking about workarounds. One thing Firefox does allow, mercifully, is putting inline attributes into the DOM. So here's a partial strategy:

    1. Replace each inline style in the html document with a corresponding "nStyle", e.g., ...

    2. When the page is loaded, do the following with each element node: (a) copy the value of the nStyle attribute into the tag's cssText, and at the same time (b) convert the nonstandard attributes into an easier format, so that, e.g., node.getAttribute('nStyle') becomes the object {"nref":"#myid", "foo":"bar"}.

    3. Write a "calculatedStyle" function that gets either the style or the nStyle, depending on what's available.

    Writing a rough parser for style sheets might enable a similar strategy for them, but I have a question: How do I get over the hurdle of reading the style sheet without censorship from Firefox?

提交回复
热议问题