Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #11720

Re: getComputedStyle vs currentStyle with IE 9

Message-ID <2261546.FRqVoOGUtd@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-02-12 10:59 +0100
Subject Re: getComputedStyle vs currentStyle with IE 9
Newsgroups comp.lang.javascript
Followup-To comp.lang.javascript
References (5 earlier) <1953157.aqSPkdTlGX@PointedEars.de> <gJmdnTVTqeAWxqvSnZ2dnUVZ_g-dnZ2d@westnet.com.au> <6101254.HsSKKp0Gan@PointedEars.de> <1395223.HDI7Dnh15d@PointedEars.de> <iLSdnWqUiawV76rSnZ2dnUVZ_qCdnZ2d@westnet.com.au>

Followups directed to: comp.lang.javascript

Show all headers | View raw


Andrew Poulos wrote:

> On 12/02/2012 1:21 AM, Thomas 'PointedEars' Lahn wrote:
>> Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> I think you are misleading me as it doesn't look like there's a better
>>>> way.
>>> Wrong on both accounts.  For crying out loud, a *closely related*
>>> question has been asked (presumably, *again*) on StackOverflow
>>> *yesterday*, and I
> 
> So, I don't normally read StackOverflow.

OMG.  Google is your friend!
 
> 1.
> document.defaultView.getComputedStyle(el,
> null).getPropertyValue("background-color")

Standards-compliant.

> 2.
> document.defaultView.getComputedStyle(el, null)["backgroundColor"]

Standards-compliant (but optional).

> 3. document.defaultView.getComputedStyle(el,
> null).getPropertyValue("backgroundColor")

Not standards-compliant, not supposed to work.

> 4.
> document.defaultView.getComputedStyle(el, null)["background-color"]

Not standards-compliant, not supposed to work.

> 5.
> el.currentStyle["background-color"]

MSHTML-proprietary, but not supposed to work this way.
 
> 6.
> el.currentStyle["backgroundColor"]

MSHTML-proprietary; supposed to work *there*.

> where 'el' is a DIV with a bg colour set and this is what I got:
> 
> IE 9
> ----
> 1. correct colour
> 2. correct colour
> 3. ""

All as expected.

> 4. correct colour
> 5. correct colour

Both unexpected, but then again I never waste time testing *wrong* 
approaches.

> 6. correct colour

As expected.

> Opera 11.61
> -----------
> 1. correct colour
> 2. correct colour
> 3. ""
> 4. undefined
> 5. undefined
> 6. correct colour

All as expected.  Opera has a long history of emulating MSHTML while trying 
to be standards-compliant at the same time.

> Safari 5.1.2
> ------------
> 1. correct colour
> 2. correct colour
> 3. null
> 4. correct colour

All as expected.

> 5. error
> 6. error

Of course it gives an error in WebCore.  It's MSHTML-proprietary, for 
goodness' sake!

> Firefox 10.0.1
> --------------
> 1. correct colour
> 2. correct colour
> 3. ""
> 4. undefined

All as expected.

> 5. error
> 6. error

See above.  However, you have neglected to test potential differences 
between Standards Compliance and Quirks Mode in all cases.  It is possible 
that `currentStyle' is available in Gecko's Quirks Mode as is 
`document.all'.

> Chrome 17.0.963.46
> ------------------
> 1. correct colour
> 2. correct colour
> 3. null
> 4. correct colour
> 5. error
> 6. error

Chrome's/Chromium's layout engine is (based on) WebCore.  See above.
 
> 1 and 2 appear to be the most consistent.

Few surprises (t)here.

> Thanks for the time you spent helping me on this.

Hm, hm.


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

getComputedStyle vs currentStyle with IE 9 Andrew Poulos <ap_prog@hotmail.com> - 2012-02-10 23:02 +1100
  Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-10 13:38 +0100
    Re: getComputedStyle vs currentStyle with IE 9 Andrew Poulos <ap_prog@hotmail.com> - 2012-02-10 23:48 +1100
      Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-10 13:55 +0100
        Re: getComputedStyle vs currentStyle with IE 9 Andrew Poulos <ap_prog@hotmail.com> - 2012-02-11 06:48 +1100
          Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-10 23:46 +0100
            Re: getComputedStyle vs currentStyle with IE 9 Tim Streater <timstreater@greenbee.net> - 2012-02-10 22:51 +0000
              Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-11 11:55 +0100
            Re: getComputedStyle vs currentStyle with IE 9 Andrew Poulos <ap_prog@hotmail.com> - 2012-02-11 23:13 +1100
              Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-11 14:41 +0100
                Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-11 15:21 +0100
                Re: getComputedStyle vs currentStyle with IE 9 Andrew Poulos <ap_prog@hotmail.com> - 2012-02-12 19:04 +1100
                Re: getComputedStyle vs currentStyle with IE 9 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-12 10:59 +0100
  Re: getComputedStyle vs currentStyle with IE 9 Captain Paralytic <paul_lautman@yahoo.com> - 2012-02-10 05:37 -0800

csiph-web