miscoded

the web is a hack

document.all offers another IE quirk

To finish off a trio of posts about IE oddities, another site with subtle problems demonstrates yet another quirk.

The site uses the outdated document.all syntax.

document.all is the main collection of IE's original document object model. It contains all elements in the document, and you can access individual elements with normal JavaScript bracket notation: document.all[0] or document.all['someElementID'] .

It is less known that in addition to the normal bracket syntax one can also use round brackets - like in a function call. document.all(0) is equivalent to document.all[0]. I don't know why IE supports this, perhaps to cater for newbie JavaScript authors who don't distinguish properly between square and round brackets?

The Maltanet site uses the less familiar syntax document.all() with various arguments. Some of the arguments have the value null. It turns out that while document.all[null] is undefined (as one expects), document.all(null) returns the first element in the document!

Not suprisingly, this quirk evaded both FireFox and Opera when they implemented their document.all support. Hence the menus on this particular page will only work in IE.

IE's event transparency logicCross-browser compatibility matters!

Comments

Hallvord R. M. Steenhallvors Tuesday, September 6, 2005 2:34:07 PM

An enlightening comment by E-mail from Joshua Paine:

I got to reading your miscoded journal from Scott Andrew LePera. I notice in the pages I have read that a couple times you wonder aloud why IE allows () where it should only allow [] in JavaScript. Beyond or complementing the 'embrace and extend' theory, I'm pretty confident it has something to do with making VB[Script] writers comfortable. VB, of course, is Microsoft's baby, and they seemed to hope to supplant JavaScript on web pages with VBScript. And VB uses () for indexing arrays and hashes as well as for calling functions.

qicai02 Tuesday, May 30, 2006 8:19:27 AM

party drunk

qicaispace Friday, July 7, 2006 2:38:03 PM

hi

João EirasxErath Wednesday, November 1, 2006 3:56:01 AM

The solution for this would be, make document.all a function, the toString() method return "object", fill it up with the elements, and change all properties like length and bla bla bla.
Then hide it p

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.