Netscape 4.x Compatibility Issue

Discussion in 'Javascript' started by Jon, Jun 15, 2004.

  1. Jon

    Jon Guest

    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, Jun 15, 2004
    #1
    1. Advertising

  2. Jon

    Matt Kruse Guest

    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/
     
    Matt Kruse, Jun 15, 2004
    #2
    1. Advertising

  3. Jon

    Mark Preston Guest

    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.
     
    Mark Preston, Jun 15, 2004
    #3
  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;
    > 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
     
    Douglas Crockford, Jun 15, 2004
    #4
  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
     
    Thomas 'PointedEars' Lahn, Jun 15, 2004
    #5
  6. Jon

    Matt Kruse Guest

    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/
     
    Matt Kruse, Jun 15, 2004
    #6
  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...:)
     
    Yann-Erwan Perio, Jun 15, 2004
    #7
  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
     
    Thomas 'PointedEars' Lahn, Jun 16, 2004
    #8
  9. Jon

    Randy Webb Guest

    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/
     
    Randy Webb, Jun 16, 2004
    #9
  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.
     
    Yann-Erwan Perio, Jun 16, 2004
    #10
  11. Jon

    Grant Wagner Guest

    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 <>

    * 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
     
    Grant Wagner, Jun 17, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TUxpYmJ5?=

    Netscape - Backward compatibility testing

    =?Utf-8?B?TUxpYmJ5?=, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    633
    [MSFT]
    Sep 6, 2004
  2. Ashwini Khanna

    IE and Netscape compatibility for ASP.NET

    Ashwini Khanna, Jan 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    675
    Ashwini Khanna
    Jan 20, 2005
  3. Federico Bari
    Replies:
    3
    Views:
    442
    Mark Parnell
    Sep 5, 2003
  4. Ruskin
    Replies:
    2
    Views:
    144
    Aaron Bertrand [MVP]
    Apr 15, 2004
  5. Federico Bari

    ** IE5, IE6 and NETSCAPE COMPATIBILITY PROBLEM **

    Federico Bari, Sep 4, 2003, in forum: Javascript
    Replies:
    4
    Views:
    121
    Federico Bari
    Sep 6, 2003
Loading...

Share This Page