Netscape 4.x Compatibility Issue

J

Jon

Hi,

I have a function that uses the following line:

var level = document.getElementById( id);

I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn't work... What can I do to get
the same element in this browser? Thanks!

Jon
 
M

Matt Kruse

Jon said:
var level = document.getElementById( id);
I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn't work... What can I do to get
the same element in this browser? Thanks!

Since netscape 4.x doesn't support getElementById(), it gets complicated.
What type of element are you trying to get the position of?

I wrote this small library to get the position of <a> elements, which
Netscape4.x does support. It's not always pretty, but if you can put an <a>
tag somewhere and use that as a reference, it allows positioning of objects
relative to the <a> in netscape4:
http://www.javascripttoolbox.com/anchorposition/
 
M

Mark Preston

Jon said:
Hi,

I have a function that uses the following line:

var level = document.getElementById( id);

I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn't work... What can I do to get
the same element in this browser? Thanks!

Jon
Jon,

Netscape 4 (along with most other older browsers) does not support the
use of "getElementById()" or, in fact, most of the rest of the modern
DOM either. The "backward-compatible" stuff, of course, is fine but not
the newer stuff.

So, in a nutshell, you need to ask yourself just how much you want to
support these older browsers. Is it worth the effort? Would it be easier
to ask your users to upgrade to modern browsers? How many users are
affected by the problem? If you find you really do need to support these
older browsers then it is certainly possible to use older versions of
code that will do the same or similar things - but for obvious reasons
that means you will have a much harder time maintaining the code and
testing the software.
 
D

Douglas Crockford

I have a function that uses the following line:
Matt and Mark have both posted good ideas.

The following is from the X Library, licensed LGPL
(http://cross-browser.com/). You don't have to use the library, but this
should give you some ideas.

function xGetElementById(e)
{
if(typeof(e)!='string') return e;
if(document.getElementById) e=document.getElementById(e);
else if(document.all) e=document.all[e];
else if(document.layers) e=xLayer(e);
else e=null;
return e;
}
function xLayer(id,root)
{
var i,layer,found=null;
if (!root) root=window;
for(i=0; i<root.document.layers.length; i++) {
layer=root.document.layers;
if(layer.id==id) return layer;
if(layer.document.layers.length) found=xLayer(id,layer);
if(found) return found;
}
return null;
}


Be prepared for lots of heartache and misery if you choose this path.
xGetElementById will only return an html element reference if the the
element is a <layer> or a <div> with a style=position:absolute. It will
fail in all other cases.

There are two big reasons why Netscape lost the browser wars. The first
was the abusive business practices of Microsoft. The second is that
Netscape shipped a badly designed browser, putting time-to-market way
ahead of all other considerations.

Netscape does not support 4.x. Neither should you.

http://www.crockford.com/javascript/javascript.html
 
T

Thomas 'PointedEars' Lahn

Mike said:
The following is from the X Library, licensed LGPL (http://cross-browser.com/). You don't have to use the library, but this should give you some ideas.

Your lines should end at 80 columns at max. A length around 76 columns
per line is recommended since it allows your postings to be quoted
within 80 columns (allowing the quotes to be read on a text terminal)
without additional wrapping.
function xGetElementById(e)
{
if(typeof(e)!='string') return e;
if(document.getElementById) e=document.getElementById(e);
else if(document.all) e=document.all[e];
else if(document.layers) e=xLayer(e);
else e=null;
return e;
}

This is bordering to wrong, as ECMAScript and implementations are not
strictly typed. One can pass a numeric value to document.all and as
index of document.layers, where (according to the MSDN Library)
document.all should be called as a *method*, not accessed as a
non-function property with properties (it may also work with square
bracket accessor, though). Besides, "typeof" is an operator, not a
method, so the parantheses can be omitted.


PointedEars
 
M

Matt Kruse

Douglas said:
Netscape does not support 4.x. Neither should you.

I'm _very_ happy that as of this year, NN4.x support is being dropped from
almost all the client requests that I've seen. Finally...
 
Y

Yann-Erwan Perio

Thomas said:
where (according to the MSDN Library)
document.all should be called as a *method*, not accessed as a
non-function property with properties (it may also work with square
bracket accessor, though).

document.all is not restricted to IE, and other UA's might implement it
as a collection and not a method - in which case using the array
accessor would at least permit a fallback (you could also test typeof
document.all=="function" to definitely kill the problem).


Just some thoughts...:)
 
T

Thomas 'PointedEars' Lahn

Yann-Erwan Perio said:
document.all is not restricted to IE,

Correct. Apparently you are referring to something I did not write.
and other UA's might implement it as a collection and not a method -

Why would they? If they are implementing document.all it is most
certainly because they want the UA to be "IE compatible". It would
be foolish to implement document.all other than specified because
that would break the compatibility wished for.


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn wrote:

Why would they?

Obviously, you have never seen a script that assumes that the presence
of document.all is assumed to mean its IE, and it has nothing to do with
whether its actually implemented the same as it is in IE.

If they are implementing document.all it is most
certainly because they want the UA to be "IE compatible".

No, they want it to pass this test:
if (document.all)
It would be foolish to implement document.all other than specified
because that would break the compatibility wished for.

That depends on the level of "compatability" wished for.
 
Y

Yann-Erwan Perio

Thomas said:

Thank you:)
Apparently you are referring to something I did not write.

Actually I was simply commenting on the fact that document.all should be
called as a *method* according to MSDN (though they use the expression
"document.all collection" quite frequently in the reference)- while I'd
advise using it with the array-like accessors, for the reasons explained
precedently.

Anyway, that was a mere remark, sorry if I've been unclear.


Regards,
Yep.
 
G

Grant Wagner

Yann-Erwan Perio said:
Actually I was simply commenting on the fact that document.all should be
called as a *method* according to MSDN (though they use the expression
"document.all collection" quite frequently in the reference)- while I'd
advise using it with the array-like accessors, for the reasons explained
precedently.

document.all is a collection, since it can be accessed using square bracket
array notation: document.all[...].

The confusions is that collections in IE can also be accessed using "method
notation" or "vbscript array notation" or whatever you want to call it:
document.all(...), document.forms(...).elements(...), etc. which can lead to
massive confusion (and the source of many errors in other user agents).

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top