Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19367
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Accessing image property in IE when there's a period in the html ID? |
| Date | 2013-04-19 19:40 +0200 |
| Organization | albasani.net |
| Message-ID | <kkrvi1$ipe$1@news.albasani.net> (permalink) |
| References | (2 earlier) <1411375.u70iIU05oh@PointedEars.de> <kkogbh$muh$1@dont-email.me> <19825448.DougqSLUUr@PointedEars.de> <kkp0g9$jrf$1@news.albasani.net> <7369980.0fbq9E8MqD@PointedEars.de> |
On 2013-04-19 01:25, Thomas 'PointedEars' Lahn wrote:
> Stefan Weiss wrote:
>> How can you call document.getElementById(id) more error-prone than
>> document.images[id], when the topic of this very thread is an error
>> caused by the unexpected and poorly documented behavior of
>> document.images?
>
> It was not. It was caused by using invalid markup, and DOM scripting on
> that markup.
That's a distortion of facts. First of all, the id value "0010.0" is
valid in HTML5. The problem as described still occurs in IE10 in
standards mode with a validated HTML5 document, so this cannot be the
main cause. Second, regardless of its validity, this value is accepted
as an ID by Internet Explorer (including IE8, the browser mentioned by
the OP). If it wasn't, various other methods including getElementById()
and namedItem() would fail.
The main cause of the problem was, as I said, that it's unclear and
poorly documented how browsers (and IE in particular) handle the
array-like access of HTML collections like document.images.
>> document.getElementById(id) is standardized, well documented,
>
> Non sequitur.
What?
>> and does what it says. document.images[id] is not standardized,
>
> You really need to pay more attention. I have already showed that it is
> standardized in one W3C Specification and likely going to be standardized in
> another in the not too distant future. If you count WHATWG HTML as a
> standard, it is specified in a second standard already.
>
>> not well documented,
>
> Wrong again. I have posted references to documentation already.
> Other documentation is readily available, for example
>
> <http://msdn.microsoft.com/en-us/library/ms537461.aspx>
> <https://developer.mozilla.org/en-US/docs/DOM/document.images>
Maybe _you_ should have paid better attention. Yes, document.images is
standardized and documented, but what happens when it's directly
accessed as an array is not. That's the whole point: the accessor
methods in document.images do the right thing, the array-like access
fails in IE.
Your MDN link only refers to the W3C DOM Specification, which has
nothing at all to say about this.
The WHATWG HTML 5 specification also refers back to the W3C DOM specs
for HTMLCollections.
The MSDN link documents what happens when the index is a) an integer, or
b) the id or name of an element. The OP's case should fall squarely
under (b), but obviously that's not what happens. IE's behavior is
either a bug in the product or a bug in the documentation. Neither does
much to recommend it over getElementById().
By the way, kudos on finding that page. It's not indexed by Google. Bing
only finds some other similar pages after searching for a known phrase
from that page. I tried to look it up through the MSDN DOM reference,
but their page on 'document' doesn't have an 'images' property:
http://msdn.microsoft.com/en-us/library/ms535862.aspx
The Microsoft documentation sites really are a train wreck. I restate
"poorly documented".
>> and does... well, whatever the implementation thinks it should do.
>
> No, it does the same that it did before in the same browser.
So that's a "Yes".
> IOW, this behavior might be surprising to you, but to experienced developers
> it is well-known;
As a reply to this ad hominem, I'd like to quote Tim Streater. Or Götz
von Berlichingen; less topical, but the intention is the same.
> in short: it is DOM Level 0-compliant.
There's no standard for DOM-0, so there can be no compliance. You're
describing legacy behavior.
> It is no surprise
> that what you could call a bug in NN 3 is still there in IE 6 and apparently
> beyond (the OP did not post the whole markup, and which mode they used, so
> it is possible that in IE 9 Standards Mode the problem would not occur).
No, that's not possible. It's also easy enough to test, but maybe not as
much fun as speculating about what might be.
> Microsoft prides itself in achieving backwards compatibility in their
> products no matter the cost
That's a euphemism straight out of Redmond's marketing department :)
No, I get your point: it used to work this way, they don't want to break
compatibility, and that's why it still works that way. Fine, but then
they have to document it.
> IE/MSHTML 8 and 9 are _not_ HTML5-compliant, so it is no surprise that they
> would use HTML-4.01-based name resolution,
IE10 is, or claims to be. The problem still exists.
> even though the behavior of
> MSHTML with string indexes – which would probably be in specification lingo:
[snip made-up specification]
> – is *backwards-compatible*, but not W3C-DOM-compliant (no argument there).
It would have been nice if they had specified it like that, but they
haven't. So we're back to
1) not standardized
The array-like access for document.images is not specified in any
standard.
2) poorly documented
The implementations' documentation of this feature is either
absent or incorrect.
3) inconsistent across implementations
IE interprets "0010.0" as 10. Some really ancient NN versions
may have done that, too, but most current browsers don't.
QED.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Accessing image property in IE when there's a period in the html ID? Tuxedo <tuxedo@mailinator.com> - 2013-04-18 00:50 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 01:29 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 07:53 +0300
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 10:07 +0200
Re: Accessing image property in IE when there's a period in the html ID? Tuxedo <tuxedo@mailinator.com> - 2013-04-18 08:39 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 11:06 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 13:05 +0300
Re: Accessing image property in IE when there's a period in the html ID? Andrew Poulos <ap_prog@hotmail.com> - 2013-04-18 20:21 +1000
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 12:39 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 16:38 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-19 01:25 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-19 19:40 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-19 19:52 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 13:56 +0300
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 13:19 +0200
csiph-web