phani krishna
phani krishna

Reputation: 21

Is it possible to use "document.all" in IE11 without changing every usage?

I am working on old project. In which document.all() is used in JavaScript. The same command working fine in IE8, 9, 10 but does not work on IE11.

I came to know that we need to use document.getElementById(), but I need to change nearly 1000 JSP files for this change.

Please suggest - is there any alternative to make it possible?

Upvotes: 2

Views: 6755

Answers (2)

PseudoNinja
PseudoNinja

Reputation: 2856

By forcing IE11 to emulate IE10 (i used meta tags <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10"/>document.all becomes available.

jsbin

Upvotes: 0

user2864740
user2864740

Reputation: 61975

It is possible to use document.all(id) and document.all[id] in IE11/Edge - at least when site has an HTML4 doctype, and perhaps related compatibility features. It also appears to work (for me) in E11/Edge & HTML5; YMMV on this last configuration.

That is, even though it is "no longer supported" - and is even marked as removed (so YMMV outside of 'compatibility' modes) - it is still implemented in IE11. Windows XP is "no longer supported" but it continues to be used and still runs as well as it ever did .. never mind it being an abandoned ship. (The documentation alludes to only the HTML5 doctype triggering the green field behavior; although I cannot observe the claimed effects.)

Since this is an "old project" the easiest solution would be leave it alone, triggering an IE 'compatibility mode' as required; there are likely many other antiquated approaches anyway. That is, leave the site as HTML4 as this is, after all, an "old project".

While I initially suggested 'shimming'1 in a comment the property/object required is problematic for several reasons and the all[id] form cannot be emulated as RobG pointed out. Also, such a shim wouldn't actually update the code to use the approved methods - it'd just be a lie and run counter to the reason why such was removed to begin with.

Thus, if desiring change the deprecated/obsolute usage the proper solution is to modify the "1000 JSP files". With a little bit of analysis this ought to be possible with a mostly-automated global replacement followed by a diff/delta code-review.


1FWIW, the most basic shim, assuming that reassignment to document.all is possible in IE11-where-document.all-is-really-removed, would be something like:

if (!document.all) {
   document.all = document.getElementById;
}

This would allow document.all(someId) but not all(name), all[id], all.length, or all.item(id). The current usage of document.all would still need to looked at to make sure the shim covered existing usages; and the few usages that are not covered should be updated wholesale.

If such a shim was sufficient it would still need to be injected into all the "1000 JSP files"; hopefully there is already a common script file ..

Upvotes: 4

Related Questions