The final 'document.getElementById' fix - test on old browser needed ?

A

Aaron Gray

Hi,

I know the 'document.getElementById()' issue is really over since every
browser since 1998 supports the W3C DOM standard, but I could not resist
this offering :-

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

This should then provide a getElementById function if one does not already
exist.

Is anyone in a position to be able to test this code ?

You could go thurther and define :-

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

Reference :-

http://www.jibbering.com/faq/faq_notes/not_browser_detect.html

Thanks,

Aaron
 
B

Bjoern Hoehrmann

* Aaron Gray wrote in comp.lang.javascript:
I know the 'document.getElementById()' issue is really over since every
browser since 1998 supports the W3C DOM standard, but I could not resist
this offering :-

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

This should then provide a getElementById function if one does not already
exist.

Is anyone in a position to be able to test this code ?

There's http://browsers.evolt.org and there are a number of free virtual
machine http://en.wikipedia.org/wiki/Category:Virtualization_software
products that you can use to set up old operating systems or just iso-
lated enviroments to run them.
 
S

Svend Tofte

document.getElementById = function(id) { return document.layers[id]; }

NS4 Layers are more tricky then that. Layers that are nested will not
be exposed through the top level layers array. Example

document.layers['outerLayer'].document.layers['innerLayer'] (yes, it's
that messed up)

Regards,
Svend
 
L

Lasse Reichstein Nielsen

Svend Tofte said:
document.getElementById = function(id) { return document.layers[id]; }

NS4 Layers are more tricky then that. Layers that are nested will not
be exposed through the top level layers array. Example

document.layers['outerLayer'].document.layers['innerLayer'] (yes, it's
that messed up)

Also, layers is not the only collection worth checking. I would also
check document.images, document.links, etc., for each of the nested
documents, in order to better simulate document.getElementById.

Well, to be honest, I'd prefer to just drop support for Netscape 4.

/L
 
A

Aaron Gray

Lasse Reichstein Nielsen said:
Svend Tofte said:
document.getElementById = function(id) { return document.layers[id]; }

NS4 Layers are more tricky then that. Layers that are nested will not
be exposed through the top level layers array. Example

document.layers['outerLayer'].document.layers['innerLayer'] (yes, it's
that messed up)

Also, layers is not the only collection worth checking. I would also
check document.images, document.links, etc., for each of the nested
documents, in order to better simulate document.getElementById.

Well, to be honest, I'd prefer to just drop support for Netscape 4.

Right :)

Thanks,

Aaron
 
A

Aaron Gray

Aaron Gray said:
Hi,

I know the 'document.getElementById()' issue is really over since every
browser since 1998 supports the W3C DOM standard, but I could not resist
this offering :-

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

This should then provide a getElementById function if one does not already
exist.

Is anyone in a position to be able to test this code ?

There's a test for document.getElementById() emulation here :-

http://www.aarongray.org/Test/JavaScript/document.getElementById-test.html

Thanks,

Aaron
 
D

Dr J R Stockton

In comp.lang.javascript message said:
I know the 'document.getElementById()' issue is really over since every
browser since 1998 supports the W3C DOM standard, but I could not resist
this offering :-

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

This should then provide a getElementById function if one does not already
exist.

Is anyone in a position to be able to test this code ?

A version tested in MS IE 4 is at <URL:http://www.merlyn.demon.co.uk/js-
versn.htm#SSF>; I cannot repeat the test.

I don't recall anyone complaining that it did not work in the
circumstances in which I used it. But it does not reproduce all
features.

To get it rested in Netscape 4, I suggest that you ask the custodian of
the Davar site, who posts advertisements here from time to time.
Evidently he is keen to support those hoping to upgrade to Netscape 4.8.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
D

dhtml

Svend Tofte said:
document.getElementById = function(id) { return document.layers[id];}
NS4 Layers are more tricky then that. Layers that are nested will not
be exposed through the top level layers array. Example
document.layers['outerLayer'].document.layers['innerLayer'] (yes, it's
that messed up)

For that, you'd need either DFS or BFS. DFS is probably going to be
more efficient in JS. Just keep growing the array.
Also, layers is not the only collection worth checking. I would also
check document.images, document.links, etc., for each of the nested
documents, in order to better simulate document.getElementById.

Well, to be honest, I'd prefer to just drop support for Netscape 4.

And even with an traversal that accounted for all of that, the result
would still be slow and would miss elements in NS4 (document.body, for
example).

It seems like a lot of bloat just for NS4 support.

The MSIE id/name bug seems to be a bigger concern:
http://www.gtalbot.org/BrowserBugsSection/MSIE8Bugs/#bug11
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top