Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11576
| Message-ID | <6101254.HsSKKp0Gan@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-02-11 14:41 +0100 |
| Subject | Re: getComputedStyle vs currentStyle with IE 9 |
| Newsgroups | comp.lang.javascript |
| References | (2 earlier) <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 |
Followups directed to: comp.lang.javascript
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
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