473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Netscape 4.x Compatibility Issue

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
Jul 23 '05 #1
11 1488
Jon wrote:
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/

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #2
Jon wrote:
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.
Jul 23 '05 #3
On 15 Jun 2004 07:27:08 -0700, Jon <jm*****@jonathanludwig.com> wrote:
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


Hi Jon,

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[i];
if(layer.id==id) return layer;
if(layer.document.layers.length) found=xLayer(id,layer);
if(found) return found;
}
return null;
}
Jul 23 '05 #4
>> 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!
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[i];
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
Jul 23 '05 #5
Mike Foster schrieb:
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
--
http://pointedears.de/scripts/dhtml.js
Jul 23 '05 #6
Douglas Crockford wrote:
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...

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #7
Thomas 'PointedEars' Lahn wrote:
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...:-)
Jul 23 '05 #8
Yann-Erwan Perio schrieb:
Thomas 'PointedEars' Lahn wrote:
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,


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
Jul 23 '05 #9
Thomas 'PointedEars' Lahn wrote:

and other UA's might implement it as a collection and not a method -

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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #10
Thomas 'PointedEars' Lahn wrote:
Correct.
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.
Jul 23 '05 #11
Yann-Erwan Perio wrote:
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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some...
4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
13
by: kaeli | last post by:
Can anyone explain this to me? It's driving me insane. Save this and run it in IE or Opera and then in Mozilla or Netscape 6+. In IE/Opera, I get the expected 4 alerts. In Mozilla/Netscape, I...
26
by: Roger Desparois | last post by:
Hi, I need help : I found the simplest and most precise way to open and close submenu layers. it works perfectly with IE, but for some odd reason NS won't recognize it. Can anyone tell me why...
3
by: Don | last post by:
I can successfully force submission of a <form> using "document.formname.submit()". But, the submission doesn't appear to occur when used with Netscape. Anybody know why this is happening, and...
3
by: VK | last post by:
<http://browser.netscape.com/ns8/> The biggest hecs: Two totally separate, including scripting, parsing engines: Mozilla/Firefox (called "Netscape") and Internet Explorer. User can choose any...
2
by: Dominic | last post by:
Hi everybody, I'm planning to use serialization to persist an object (and possibly its child objects) in my application. However, I'm concerned about the backward compatibility issue. I'm...
1
by: MLibby | last post by:
I'm a Netscape newbie and am using it for backward compatibility testing. How do I debug javascript in Netscape? I set Netscape as the default debugger (design mode | file | Browse With) and I am...
2
by: Ashwini Khanna | last post by:
Hi Everybody! I have a browser compability issue with ASP.NET pages. I have created a small web-site in ASP.NET, tested it with IE - all was well till then. Then my client required me to test on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.