isIE=document.all; //only kind of true - Jon Galloway

isIE=document.all; //only kind of true

Internet Explorer 4 used document.all['elementName'] to refer to document elements while waiting for the W3C standard, which turned out to be document.getElementById('elementName'). IE 5 and above, plus all other modern standards based browsers, all support document.getElementByID(). IE 4 usage was below .5% in 2002 and isn't even being tracked anymore, so there's no good reason to be using document.all anymore.

Firefox developers decided to partially support this non-standard syntax since so many pages are still using it. It was probably a good decision - if they didn't, people would decide that Firefox was no good since it couldn't run their favorite pages, even though real problem was buggy webpages.

On the other hand, they didn't want to encourage use of non-standards compliant code, and they certainly didn't want to break all those poorly written scripts that (incorrectly) assumed the following:
isIE=document.all;

So Firefox supports document.all, but says it doesn't. That means it can evaluate document.all['elementName'], but alert(document.all) shows false.

This behavior makes some sense, but can result in some weird behavior. Scripts that were written for IE only (using document.all[] syntax) will work in Firefox, but scripts which test for IE with document.all but don't include proper handling for non-IE browsers don't work.

There are some much better solutions to the document.all mess:

1. Obviously, the best is to convert from document.all[] to document.getElementById(). It's standards compliant, works in 99+% of browsers, has a great beat, and is easy to dance to. Usually it's a simple find / replace exercise. However, it's sometimes not practical when you've got legacy scripts or browsers to deal with.

2. If you have to support IE 4 David Emmerson came up with a great work-around: add document.getElementById support to IE4 with this little script:

if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

3. If you absolutely have to write browser dependant code, use a decent browser detection script. This one is pretty solid: http://webreference.com/tools/browser/javascript.html

The best general approach is to check for support of a feature rather than to sniff IE and apply IE / non-IE logic. If you need to determine if you're looking at IE, you can just ask nicely (does navigator.appName = 'MSIE'?).

Of course, cross browser Javascript is a complex subject. Here are some good references:
http://www.stopbadtherapy.com/standards.shtml
http://www-128.ibm.com/developerworks/web/library/wa-ie2mozgd/
powered by IMHO 1.2

Published Sunday, August 07, 2005 5:23 AM by Jon Galloway

Comments

# re: isIE=document.all; //only kind of true

I thing it's pretty foolish to ever check the appName. Suggesting it at all should carry the strongest of warnings.

I'm sure that there are instances where you will want to check what browser your dealing with but I should hope that those cases will be followed by a redirect to upgrade or a stats database to insert that data into.

Also, if there is some instance where you need to have browser specific code, the version should also be checked in such a way that the code assumes future versions will work with the latest code.

David Emmerson's work around looks like it should work great. According to my stats I havn't had an IE4 visitor in years though. Probably best just to redirect to a polite "Sorry Grandma, You need to upgrade" message. :-)

Sunday, August 07, 2005 3:03 PM by Collin Yeadon

# re: isIE=document.all; //only kind of true

Agree, Collin. My point is that it's even worse to pick one feature as an indicator of which browser you're working with and make assumptions based on that one feature. The script

appName based is also a problem because of UserAgent spoofing. I regularly set my UserAgent to MSIE or GoogleBot to get past stupid JS check scripts that say only allow IE.

The best option is to write standards compliant JS when it's broadly supported, and in this case it is.

Sunday, August 07, 2005 3:49 PM by Jon Galloway

# re: isIE=document.all; //only kind of true

So how to solve this in firefox: document.all.tablefiles.deleteRow();

Tuesday, December 11, 2007 4:41 AM by selina

# re: isIE=document.all; //only kind of true

@selina Try this:

document.getElementById('tablefiles').deleteRow();

Tuesday, December 11, 2007 12:28 PM by Jon Galloway

# re: isIE=document.all; //only kind of true

Oh, I solved it.

should be as follow:

document.getElementById('tablefiles').deleteRow(0);

but I don't know why has to be like this

if 'insertRow' should be(just an example):

inner=document.getElementById("tablefiles").insertRow(-1);

inner.insertCell(0).innerHTML="hellovvvvvv";

We should specify the number about Where to insert and where to delete.

Thank you!!! JOn

Tuesday, December 11, 2007 10:42 PM by Selina

Leave a Comment

(required) 
(required) 
(optional)
(required)