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


Groups > comp.lang.javascript > #11576

Re: getComputedStyle vs currentStyle with IE 9

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eweka.nl!lightspeed.eweka.nl!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <6101254.HsSKKp0Gan@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Sat, 11 Feb 2012 14:41:37 +0100
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
Subject Re: getComputedStyle vs currentStyle with IE 9
Newsgroups comp.lang.javascript
References <F6-dnVFAkI3TmqjSnZ2dnUVZ_sidnZ2d@westnet.com.au> <2541188.UZlinSPExI@PointedEars.de> <0ZKdnfcGHO2Bj6jSnZ2dnUVZ_rSdnZ2d@westnet.com.au> <5429156.TnbMflxdSq@PointedEars.de> <5umdnQMO8OI36ajSnZ2dnUVZ_oKdnZ2d@westnet.com.au> <1953157.aqSPkdTlGX@PointedEars.de> <gJmdnTVTqeAWxqvSnZ2dnUVZ_g-dnZ2d@westnet.com.au>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 89
NNTP-Posting-Date 11 Feb 2012 14:41:38 CET
NNTP-Posting-Host d8fc0e2d.newsspool2.arcor-online.net
X-Trace DXC=P8\ZeDJH`kSV0Pe9PRnbJ\A9EHlD;3YcR4Fo<]lROoRQ8kF<OcfhCO[5EF936Ae=FTDZm8W4\YJN\b@mF9jNikdUS5D:Y6@85_Wk>89bc?cfcY
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:11576

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Andrew Poulos wrote:

> On 11/02/2012 9:46 AM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> On 10/02/2012 11:55 PM, Thomas 'PointedEars' Lahn wrote:
>>>> Andrew Poulos wrote:
>>>>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>>>>>> Andrew Poulos wrote:
>>>>>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>>>>>> property names. So I tried this
>>>>>>>
>>>>>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>>>>>>       if (window.getComputedStyle) {
>>>>>>>         return document.defaultView.getComputedStyle(el,
>>>>>>> null).getPropertyValue(cssPropName) ||
>>>>>>>                document.defaultView.getComputedStyle(el,
>>>>>>> null).getPropertyValue(IEcssPropName);
>>>>>>>
>>>>>>>       } else if (el.currentStyle) {
>>>>>>>         return el.currentStyle[IEcssPropName];
>>>>>>>       }
>>>>>>>
>>>>>>>       return null;
>>>>>>> }
>>>>>>>
>>>>>>> and it seems to work. Is there a better way?
>>>>>> Yes.
>>>>> Good, could you tell what it is?
>>>> Yes.
>>>> (This would actually be funny for me if it was not so disappointing.)
>>> Its disappointing to me as well.
>> All you need to do is asking a *smart* question.
> 
> 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 
have commented on the other answers there, eventually referring to 
JSX:css.js (which does not consider getPropertyValue() yet – as the 
shorthand is optional, and potentially less efficient thanks to camel-casing 
–, but soon):

<http://stackoverflow.com/questions/9216951/getting-value-of-a-css-
element/9216996>

Information about this subject can be *easily* found with Google, for 
example:

<http://lmgtfy.com/?q=currentStyle+getComputedStyle+IE>¹

(Feel stupid now?  Because you should.)
 
> One option I found is to put the currentStyle test first

It is wrong to put the `currentStyle' test and branch first.  Proprietary 
approaches should only be the fallback or alternative to standards-compliant 
ones.  Not only because the former are more error-prone, but also because 
they can be removed easier once they are not needed anymore.

> but that doesn't really resolve the fact getComputedStyle will fail with
> IE 9 and camel-cased CSS properties.

Wrong (just tested again).  getComputedStyle() "fails" with IE 
9(.0.8112.16421 on Windows 7) in *Compatibility* Mode, but not in Standards 
Mode, and it "fails" in IE < 9, of course.

<http://ie.microsoft.com/testdrive/HTML5/getComputedStyle/>

(That URL is from the first page of Google hits.  "HTML5" is M$'s marketing 
department talking, though; this method is part of W3C DOM Level 2 *Style*, 
and HTML5 refers to DOM Level 3 *Events* only.

Related URLs:

<http://en.wikipedia.org/wiki/Internet_Explorer_9#DOM>
<http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx>)

*A little bit* of browsing through the MSDN Library (using the tree view on 
the left-hand side in Classic View) shows:

<http://msdn.microsoft.com/en-us/library/ff975168(VS.85).aspx>


PointedEars
___________
¹ <http://www.google.com/search?q=currentStyle+getComputedStyle+IE&filter=0>
-- 
When all you know is jQuery, every problem looks $(olvable).

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