Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <2261546.FRqVoOGUtd@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 12 Feb 2012 10:59:46 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: getComputedStyle vs currentStyle with IE 9 Newsgroups: comp.lang.javascript Followup-To: comp.lang.javascript References: <2541188.UZlinSPExI@PointedEars.de> <0ZKdnfcGHO2Bj6jSnZ2dnUVZ_rSdnZ2d@westnet.com.au> <5429156.TnbMflxdSq@PointedEars.de> <5umdnQMO8OI36ajSnZ2dnUVZ_oKdnZ2d@westnet.com.au> <1953157.aqSPkdTlGX@PointedEars.de> <6101254.HsSKKp0Gan@PointedEars.de> <1395223.HDI7Dnh15d@PointedEars.de> Supersedes: <1936854.aqSPkdTlGX@PointedEars.de> MIME-Version: 1.0 Lines: 136 NNTP-Posting-Date: 12 Feb 2012 10:59:47 CET NNTP-Posting-Host: f4f23ca3.newsspool2.arcor-online.net X-Trace: DXC=E`BONgC<28h>jlK2>IgHGdA9EHlD;3Ycb4Fo<]lROoRa8kF 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