Netscape compatibility

Discussion in 'Javascript' started by Roger Desparois, Oct 9, 2004.

  1. 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 ?

    And is there a way around the problem ?

    I really like the elegance of this code and would like to keep using it.

    Thanks in advance.


    Roger Desparois


    <head
    <script language="Javascript"`>
    <!--
    function Pop(name){
    eval("document.all."+name+".style.visibility='visible'");
    }
    function Wop(name){
    eval("document.all."+name+".style.visibility='hidden'");
    }

    //-->
    </script>
    </head>

    <body>
    <div id="prod"
    Style="background-color:#ff0000;Position:Absolute;Left:39px;Top:89px;Width:1
    78px;Height:16px;Visibility:visible;z-index:31" onmouseover="Pop('smprod')"
    onmouseout="Wop('smprod')">
    <table width="178" height="16" border="0" cellspacing="0" cellpadding="0"
    class="menu">
    <tr>
    <td align="center" valign="middle">Volleyball</td>
    </tr>
    </table>
    </div>

    <div id="smprod"
    Style="background-color:#ff0000;text-align:right;Position:Absolute;Left:39px
    ;Top:105px;Width:178px;Visibility:hidden;z-index:32"
    onmouseout="Wop('smprod')" onmouseover="Pop('smprod')">
    <table width="178" border="0" cellspacing="0" cellpadding="0" class="menu">
    <tr>
    <td><img src="../images/espace1px.gif" width="178" height="5"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <a href="../volleyball/en-ballons.html">Balls</a><br>
    <a href="../volleyball/en-souliers.html">Shoes</a><br>
    <a href="../volleyball/en-genouillere.html">Kneepads</a><br>
    <a href="../volleyball/en-chevillere.html">Ankle braces</a><br>
    <a href="../volleyball/en-filets.html">Nets</a><br>
    <a href="../volleyball/en-accessoires.html">Accessories</a></td>
    </tr>
    <tr>
    <td><img src="../images/espace1px.gif" width="178" height="5"></td>
    </tr>
    </table>
    </div>
    </body
     
    Roger Desparois, Oct 9, 2004
    #1
    1. Advertising

  2. Roger Desparois

    VK Guest

    Leaving out the question of the code elegance... I feel you came here for a
    quick-n-dirty solution and not for a JavaScript lessons:

    <script language="Javascript"`>
    <!--
    function Pop(name){
    document.getElementById(name).style.visibility='visible';
    }

    function Wop(name){
    document.getElementById(name).style.visibility='hidden';
    }
    //-->
    </script>

    WHY??
    Because document.all is an Explorer's proprietary collection, other browsers
    do not support it.

    LATER MAY LOOK HERE:
    http://www.dynamicdrive.com/dynamicindex1/index.html
    (of course there are many similar places with even better code)
     
    VK, Oct 9, 2004
    #2
    1. Advertising

  3. "VK" <> wrote in message news:4167f9fa$0$145$...
    > Leaving out the question of the code elegance... I feel you came here for a
    > quick-n-dirty solution and not for a JavaScript lessons:
    >
    > <script language="Javascript"`>
    > <!--
    > function Pop(name){
    > document.getElementById(name).style.visibility='visible';
    > }
    >
    > function Wop(name){
    > document.getElementById(name).style.visibility='hidden';
    > }
    > //-->
    > </script>
    >
    > WHY??
    > Because document.all is an Explorer's proprietary collection, other browsers
    > do not support it.
    >
    > LATER MAY LOOK HERE:
    > http://www.dynamicdrive.com/dynamicindex1/index.html
    > (of course there are many similar places with even better code)
    >
    >
    >
    >


    Yes. documemt.all is IE. Here's a test for Netscape 6 and above I believe:

    ns6 = (!document.all && document.getElementById);
    //ns6 = true if Netscape 6+

    Netscape 4 is this:

    ns4 = (document.layers);
    //ns4 = true if Netscape 4

    ie4 = (document.all && !document.getElementById);
    // ie4 = true Internet Explorer 4

    ie5 = (document.all && document.getElementById);
    // ie5 = true Internat Explorer 5 and up

    I'm not sure how to integrate Firefox and Opera in this scheme.

    Finally yes the scripting is fine for IE. You might consider fixing the CSS. Attributes are all lower case.
    Also the relative ../images may be able to change to /images. The trouble is that in new Microsoft web
    servers they have disabled relative adddressing without overhauling the new security relative addressing will no
    longer work.

    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #3
  4. On Sat, 09 Oct 2004 15:23:19 GMT, George Hester <>
    wrote:

    [snip]

    > Yes. documemt.all is IE.


    Opera also supports it, and I believe ICEBrowser does, too.

    [snip]

    > ns6 = (!document.all && document.getElementById);
    > //ns6 = true if Netscape 6+
    >
    > Netscape 4 is this:
    >
    > ns4 = (document.layers);
    > //ns4 = true if Netscape 4
    >
    > ie4 = (document.all && !document.getElementById);
    > // ie4 = true Internet Explorer 4
    >
    > ie5 = (document.all && document.getElementById);
    > // ie5 = true Internat Explorer 5 and up


    Browser detection, whether by interpretation of the user agent string, or
    object inference, is fundamentally flawed. You don't *need* to know what
    browser you're using, just what it's capable of doing.

    Obviously you haven't read FAQ entry, 4.26.

    > I'm not sure how to integrate Firefox and Opera in this scheme.


    You don't.

    [snip]

    > The trouble is that in new Microsoft web servers they have disabled
    > relative adddressing without overhauling the new security relative
    > addressing will no longer work.


    I'm glad I use Apache.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Oct 9, 2004
    #4
  5. "Michael Winter" <> wrote in message news:eek:psfl0sgpwx13kvk@atlantis...
    > On Sat, 09 Oct 2004 15:23:19 GMT, George Hester <>


    > Obviously you haven't read FAQ entry, 4.26.
    >
    > Michael Winter
    > Replace ".invalid" with ".uk" to reply by e-mail.


    If you gave a link to the FAQ article you mention I would read it.
    Actually this came from soneone else on the Internet it is not mine. In any case how is it flawed?
    But of course if the article you mention answers that then that is what I would be looking for. Thanks.

    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #5
  6. Roger Desparois

    Lee Guest

    George Hester said:
    >
    >"Michael Winter" <> wrote in message =
    >news:eek:psfl0sgpwx13kvk@atlantis...
    >> On Sat, 09 Oct 2004 15:23:19 GMT, George Hester =

    ><> =20
    >
    >> Obviously you haven't read FAQ entry, 4.26.
    >>=20
    >> Michael Winter
    >> Replace ".invalid" with ".uk" to reply by e-mail.

    >
    >If you gave a link to the FAQ article you mention I would read it.
    >Actually this came from soneone else on the Internet it is not mine. In =
    >any case how is it flawed?
    >But of course if the article you mention answers that then that is what =
    >I would be looking for. Thanks.


    You've been reading this newsgroup for an awfully long time
    to not know where to find the FAQ:

    http://www.jibbering.com/faq/
     
    Lee, Oct 9, 2004
    #6
  7. On Sat, 09 Oct 2004 15:54:24 GMT, George Hester <>
    wrote:

    > "Michael Winter" <> wrote in message
    > news:eek:psfl0sgpwx13kvk@atlantis..


    [snip]

    >> Obviously you haven't read FAQ entry, 4.26.


    [snip]

    > If you gave a link to the FAQ article you mention I would read it.


    The FAQ, and links to it, are posted three times a week. It exists in the
    signatures of several regular posters, and is mentioned plenty of times in
    responses to posts.

    You've posted to this group longer than I have. I shouldn't need to tell
    you where to find the article.

    > Actually this came from soneone else on the Internet it is not mine.


    So?

    > In any case how is it flawed?


    It isn't reliable and can, in some instances, entirely fail to identify
    the intended browser. Furthermore, scripts based on this technique often
    fail to work, or take advantage of new features, in future browser
    versions.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Oct 9, 2004
    #7
  8. "Lee" <> wrote in message news:...
    > George Hester said:
    > >
    > >"Michael Winter" <> wrote in message =
    > >news:eek:psfl0sgpwx13kvk@atlantis...
    > >> On Sat, 09 Oct 2004 15:23:19 GMT, George Hester =

    > ><> =20
    > >
    > >> Obviously you haven't read FAQ entry, 4.26.
    > >>=20
    > >> Michael Winter
    > >> Replace ".invalid" with ".uk" to reply by e-mail.

    > >
    > >If you gave a link to the FAQ article you mention I would read it.
    > >Actually this came from soneone else on the Internet it is not mine. In =
    > >any case how is it flawed?
    > >But of course if the article you mention answers that then that is what =
    > >I would be looking for. Thanks.

    >
    > You've been reading this newsgroup for an awfully long time
    > to not know where to find the FAQ:
    >
    > http://www.jibbering.com/faq/
    >


    well here we go. I went to the link and looked under 4.26: Here was their example that I assume is the way it is supposed to be done:

    if (document.getElementById &&
    document.getElementById('el') &&
    document.getElementById('el').style ) {
    // We know that this browser supports getElementByID and has
    // a style object, so we can set a style property.
    document.getElementById('el').style.color="red";
    }

    That looks pretty familiar.

    I didn't see anything about fundamentally flawed of what I presented earlier. Oh well thanks for the liink.

    --
    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #8
  9. "George Hester" <> writes:

    > Yes. documemt.all is IE. Here's a test for Netscape 6 and above I believe:
    >
    > ns6 = (!document.all && document.getElementById);
    > //ns6 = true if Netscape 6+


    That also matches Opera 6 (unless identifying as IE) and Opera 5, and
    possibly also Safari and Konqeror (unless they decided to support
    document.all as well).

    > Netscape 4 is this:
    >
    > ns4 = (document.layers);
    > //ns4 = true if Netscape 4


    Also matches OmniWeb.

    > ie4 = (document.all && !document.getElementById);
    > // ie4 = true Internet Explorer 4


    Also matches WebTV.

    > ie5 = (document.all && document.getElementById);
    > // ie5 = true Internat Explorer 5 and up


    Also matches Opera 7, and Opera 6 when identifying as IE.

    > I'm not sure how to integrate Firefox and Opera in this scheme.


    FireFox is based on the Mozilla project, just as the Mozilla Browser
    Suite and Netscape 6+. They act identically.

    Opera 7 is not distinguishable from IE 6 using only document.all and
    document.getElementById.


    Since there are many different browsers, and always more than an
    author expects, trying to recognize specific browsers is rarely
    a good idea. Because some people have tried doing it anyway, and
    have made pages that refuse to show themselves to some browsers,
    the users of those browsers frequently make their browser detect
    as another one, making detection even more impossible.

    If the existence of document.all/document.getElementById is releveant,
    because script is going to use those specific properties, then it
    makes sense to test for their presence. In that case, it doesn't
    matter what browser it is anyway.

    <URL:http://jibbering.com/faq/#FAQ4_26>

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 9, 2004
    #9
  10. On Sat, 09 Oct 2004 16:28:33 GMT, George Hester <>
    wrote:

    [snip]

    > well here we go. I went to the link and looked under 4.26: Here was
    > their example that I assume is the way it is supposed to be done:


    It's a way. It could be made more efficient by saving the references
    obtained rather than repeated look-up.

    > if (document.getElementById &&
    > document.getElementById('el') &&
    > document.getElementById('el').style ) {
    > // We know that this browser supports getElementByID and has
    > // a style object, so we can set a style property.
    > document.getElementById('el').style.color="red";
    > }
    >
    > That looks pretty familiar.


    When compared to what?

    > I didn't see anything about fundamentally flawed of what I presented
    > earlier. Oh well thanks for the liink.


    Hmmm.

    I take it you didn't read the linked pages in that entry.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Oct 9, 2004
    #10
  11. "Michael Winter" <> wrote in message news:eek:psfl2gwhnx13kvk@atlantis...
    > On Sat, 09 Oct 2004 15:54:24 GMT, George Hester <>
    > wrote:
    >
    > > "Michael Winter" <> wrote in message
    > > news:eek:psfl0sgpwx13kvk@atlantis..

    >
    > [snip]
    >
    > >> Obviously you haven't read FAQ entry, 4.26.

    >
    > [snip]
    >
    > > If you gave a link to the FAQ article you mention I would read it.

    >
    > The FAQ, and links to it, are posted three times a week. It exists in the
    > signatures of several regular posters, and is mentioned plenty of times in
    > responses to posts.
    >
    > You've posted to this group longer than I have. I shouldn't need to tell
    > you where to find the article.
    >
    > > Actually this came from soneone else on the Internet it is not mine.

    >
    > So?
    >
    > > In any case how is it flawed?

    >
    > It isn't reliable and can, in some instances, entirely fail to identify
    > the intended browser. Furthermore, scripts based on this technique often
    > fail to work, or take advantage of new features, in future browser
    > versions.
    >
    > [snip]
    >
    > Mike
    >
    > --
    > Michael Winter
    > Replace ".invalid" with ".uk" to reply by e-mail.


    I'm sorry Mike. I don't usually click on links unless I have an ovrriding need to. If it is to see what someone asks a question about or it may have information that I am interested in at the moment then I do. Otherwise not usually. That's just me which of course I have every right to be.

    Not reliable seems weird. Not reliable means that sometimes ie5 will be false and sometimes true based on the direction the wind is blowing using IE5. That's a weird interpreter.

    Take advantage of new features. Yes that true. But then IE 5, IE 6 NN4 NN6 ain't gonna get any newer as far as I know. So those variables I provided should always give the same vaues based on the use of those browsers. If they are not reliable then it is not an issue with the code it is an issue with the interpreter used in those browser. I didn't know that was a possibility. Thanks for pointing that out.

    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #11
  12. "Michael Winter" <> wrote in message news:eek:psfl25pvjx13kvk@atlantis...
    > On Sat, 09 Oct 2004 16:28:33 GMT, George Hester <>
    > wrote:
    >
    > [snip]
    >
    > > well here we go. I went to the link and looked under 4.26: Here was
    > > their example that I assume is the way it is supposed to be done:

    >
    > It's a way. It could be made more efficient by saving the references
    > obtained rather than repeated look-up.
    >
    > > if (document.getElementById &&
    > > document.getElementById('el') &&
    > > document.getElementById('el').style ) {
    > > // We know that this browser supports getElementByID and has
    > > // a style object, so we can set a style property.
    > > document.getElementById('el').style.color="red";
    > > }
    > >
    > > That looks pretty familiar.

    >
    > When compared to what?
    >
    > > I didn't see anything about fundamentally flawed of what I presented
    > > earlier. Oh well thanks for the liink.

    >
    > Hmmm.
    >
    > I take it you didn't read the linked pages in that entry.
    >
    > Mike
    >
    > --
    > Michael Winter
    > Replace ".invalid" with ".uk" to reply by e-mail.


    No as I explained earlier. I'm just that much of a clicker on the Net. The reason being
    I have been burned too often. I'm sure the additional links are safe. But you must understand
    that I use a Server with basically no security and signed on as Administrator. So I have to be very careful
    what I do. I can operate this way have been for a very long time. I take no risks and I know where trouble lies
    usually before it happens. Sometimes I fail but that hasn't happend since msblaster and even that was
    innocuous for me. Did have trouble with coolwebsearch but I got that one licked too.

    Oh the browser variables are in a js file called in the header. So they are never accessed but once when the
    page loads.

    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #12
  13. Roger Desparois wrote:
    > I need help : I found the simplest and most precise
    > way to open and close submenu layers.


    Simplicity is at least partly a matter of perception. One line of code
    might seem to qualify but when that line of code combines a number of
    actions, and eliminates much sensible checking and verification, the
    simplicity is only really in its appearance.

    > it works perfectly with IE, but for some odd
    > reason NS won't recognize it.


    It is not that odd a reason. Any code that employs a Microsoft
    proprietary feature should be expected to fail on a non-Microsoft
    browsers (and often on non-default configurations, or non-Windows, IE).

    > Can anyone tell me why ?


    The quick answer is the use of - document.all - as Netscape/Gecko
    browsers have traditionally not implemented it (the most recent Mozilla
    versions are implementing it as a concession to ancient code written in
    the "both browsers" days without sensible feature detection. It seems
    unlikely that a gecko browser with 'Netscape' in its name will be
    released based upon the latest Mozilla code).

    > And is there a way around the problem ?


    The simple act of showing/hiding a DOM element with CSS is achievable on
    all dynamic, and many less-dynamic, browsers. Including some relatively
    ancient browsers like Netscape 4, if the element in question is assigned
    a CSS potion value of 'absolute' or 'relative', for the effort of adding
    some extra lines of code.

    > I really like the elegance of this code and would like to
    > keep using it.


    It is a hack.

    <snip>
    > <head

    ^
    A closing '>' might be a good idea here.

    > <script language="Javascript"`>


    Script elements are required to include the TYPE attribute in HTML 4.
    The language attribute is deprecated and becomes redundant when a TYPE
    attribute is included:-

    <script type="text/javascript">

    > <!--


    These HTML comment-like sequences are unnecessary in current browser
    scripting as they were introduced to address issues with browser that
    have not been in use for some considerable time.

    > function Pop(name){
    > eval("document.all."+name+".style.visibility='visible'");
    > }


    This is what you are describing as simplicity:-

    1. Construct a string representing javascript source code.
    2. Have that executed as a javascript program in a new eval
    execution context. Starting a javascript interpreter,
    have it interpret and execute the program and return the
    result. A process consisting of:-
    A. Resolve - document - against the scope chain and
    retrieve a reference to that object (assuming it
    exists, probably a safe assumption as - document -
    is universal in HTML web browsers).
    B. Resolve - all - as a named property of that object
    and retrieve a reference to that object (it doesn't
    exist in Netscape browsers so the value retrieved
    in - undefined - not an object reference).
    C. Resolve - style - as a named property of that object
    (Netscape errors here as - all - was not an object) and
    retrieve a reference to that object (assuming it exists).
    D. Assign a string value to the - visibility - property of
    that object.

    The use of the - eval - contributes nothing to simplicity here, in the
    source code or the execution of the code. It follows from nothing but
    the author's ignorance of javascript as a language as it is being use to
    dynamically insert one identifier in a dot notation property accessor.
    Javascript has always offered the bracket notation property accessor as
    a means of referencing objects using string value valuables (and
    expressions) in place of identifiers. Simply using the bracket notation
    in place of eval produces:-

    document.all[ name ].style.visibility='visible';

    (a much simpler line of code (and much simplified execution), though
    equally error prone).

    With the exception of the - document - reference (and some would include
    that), everywhere that an assumption is made above a test to verify that
    assumption is indicated. Simplicity achieved by omitting those tests is
    not valuable simplicity.

    Adding an implementation of the minimum testing might produced code
    like:-

    function Pop(name){
    var el;
    /* Only attempt to use the - document.all -
    collection if it exists on this browser:-
    */
    if(document.all){
    el = document.all[ name ];
    }
    /* Verify that the DOM element retrieval happened
    and returned a valid/usable object reference.
    And then verify that the object reference has
    a style property:-
    */
    if(el && el.style){
    /* It should be safe (non-error producing) to
    assign a value to 'visibility' the el.style
    object (whether the browser assigned meaning
    to that action is another question):-
    */
    el.style.visibility='visible';
    }
    }

    Which has lost some of its original simplicity but will now not
    error-out.

    It still will not work with Netscape browsers as they do not implement -
    document.all -. To get round that an alternative element retrieval
    mechanism must be used. W3C Core DOM standard browsers provide a -
    document.getElementById - method that is designed to retrieve a
    reference to an element with a (unique) ID attribute that corresponds
    with the string argument provided to the method call. These browsers
    include IE 5.0+ and Netscape 6+ (and many others). This method is the
    preferred method of retrieving such element references is it is most
    wildly supported, - document.all - is now only a fall-back alternative
    for ancient browser like IE 4 (and one or two others that are not going
    to provide the - style - object anyway).

    Again it is necessary to verify that the browser facilitates -
    document.getElementByyId -, but if it does not - document.all - can be
    tried as a fall back (alternative fall-back mechanisms can be used for
    Netscape 4 under some circumstances). The modified code becomes:-

    function Pop(name){
    var el;
    /* Only attempt to use the - document.getElementById -
    if it exists on this browser:-
    */
    if(document.getElementById){
    el = document.getElementByI( name );

    }else if(document.all){ // else try - document.all -:-
    el = document.all[ name ];
    }
    /* Verify that the DOM element retrieval happened
    and returned a valid/usable object reference.
    And then verify that the object reference has
    a style property:-
    */
    if(el && el.style){
    /* It should be safe (non-error producing) to
    assign a value to 'visibility' the el.style
    object (whether the browser assigned meaning
    to that action is another question):-
    */
    el.style.visibility='visible';
    }
    }

    The fact that the branching element retrieval mechanism is needed in
    both functions, and is more involved than the original anyway, makes
    this look considerably less simple. That follows from a failure to
    recognise the real steps in this process. The first step in both the
    setting of the property to 'visible' or ' hidden' is the retrieval of
    the reference to the DOM element. Both functions must use the same
    mechanism (and potentially much other code would require the same
    facility). This suggests that element retrieval would be better done by
    one separate function.

    The notes to the newsgroup FAQ cover various approaches to implementing
    a single IDed element retrieval mechanism is some detail but a simple
    (and non-optimum) implementation might go:-

    fucntion getElementWithId(id){
    if(document.getElementById){
    return document.getElementById(id);
    }else if(document.all){
    return document.all[id];
    }else{
    return null; //no retrieval mechanism available
    }
    }

    Reducing the original function to a simple:-

    function Pop(name){
    var el = getElementWithId(name);
    /* Verify that the DOM element retrieval happened
    and returned a valid/usable object reference.
    And then verify that the object reference has
    a style property:-
    */
    if(el && el.style){
    /* It should be safe (non-error producing) to
    assign a value to 'visibility' the el.style
    object (whether the browser assigned meaning
    to that action is another question):-
    */
    el.style.visibility='visible';
    }
    }

    - and having a similar simplifying effect on the internal code of both
    functions.

    The next step in the process, the verification of and referencing of the
    style object, is also common to both functions (and again potentially
    useful elsewhere). It would be possible to re-use the element retrieval
    function code and wrap the style object handling around it, but element
    retrieval is such a generally common requirement in browser DOM
    scripting that the element retrieval function is probably best left
    available to all code and a style object retrieval function designed to
    call it for its element references. So the style object retrieval
    function could go:-

    function getStyleObjWithId(id){
    var el = getElementWithId(id);
    return (el && el.style)||el;
    }

    Reducing the original function to:-

    function Pop(name){
    var st = getStyleObjWithId(name);
    if(st){
    st.visibility='visible';
    }
    }

    - and its counterpart to:-

    function Wop(name){
    var st = getStyleObjWithId(name);
    if(st){
    st.visibility = 'hidden';
    }
    }

    Which, while not as simple as one line of code, are relatively simple
    and clear, will work on DOM standard browsers in addition to IE and will
    not error-out on any browsers. (in addition, active support for
    dinosaurs like Netscape 4, when such is possible, is now just a matter
    of using a more involved element retrieval function (as can be found in
    the FAQ notes) as everything down-stream of that is already in place and
    cross-browser).

    Richard.
     
    Richard Cornford, Oct 9, 2004
    #13
  14. "Andrew Thompson" <> wrote in message news:kby0xsx78zr4$...
    > On Sat, 09 Oct 2004 17:06:19 GMT, George Hester wrote:
    >
    > > I'm just that much of a clicker on the Net. The reason being
    > > I have been burned too often.

    >
    > You should try surfing with a browser, rather than
    > your OS component. Much safer.
    >
    > --
    > Andrew Thompson
    > http://www.PhySci.org/codes/ Web & IT Help
    > http://www.PhySci.org/ Open-source software suite
    > http://www.1point1C.org/ Science & Technology
    > http://www.lensescapes.com/ Images that escape the mundane


    I do surf with a browser. IE 5.5 to be exact. Is that the "component" you are referring to?
    If so yeah I know. But that "component" is not as intractable as you may think. Just requires a little
    extra work which sucks.

    George Hester
    __________________________________
     
    George Hester, Oct 9, 2004
    #14
  15. On Sat, 9 Oct 2004 09:33:05 -0400, Roger Desparois
    <> wrote:

    [snip]

    > NS won't recognize it.
    >
    > Can anyone tell me why ?


    The document.all collection is a Microsoft invention, support by only a
    few other browsers.

    > And is there a way around the problem ?


    Use the W3C Document Object Model (DOM). Whilst support is not 100%, it is
    better than the all collection. Optionally, you can add fallbacks to other
    element retrieval methods.

    <URL:http://www.jibbering.com/faq/faq_notes/not_browser_detect.html#bdGEID>

    > I really like the elegance of this code and would like to keep using it.


    I'm afraid that a lack of feature testing and unnecessary use of eval is
    not elegant.

    > <head
    > <script language="Javascript"`>


    The language attribute is deprecated and shouldn't be used any more. Use
    the (required) type attribute instead.

    <script type="text/javascript">

    > <!--


    Script hiding is another obsolete practice, unnecessary for the Web today.
    Remove the SGML comments.

    > function Pop(name){
    > eval("document.all."+name+".style.visibility='visible'");


    The eval here, and below, isn't necessary. Properties can be accessed
    using the bracket notation which allows the use of expressions to
    construct the property name (see
    <URL:http://www.jibbering.com/faq/faq_notes/square_brackets.html>).

    document.all[name].style.visibility = 'visible';

    However, this still lacks feature detection and a cross-browser approach
    to accessing elements.

    Before your code, you can add this:

    var getRefById = document.getElementById ?
    function(n) {return document.getElementById(n);}
    : document.all ?
    function(n) {
    var e = document.all[n] || {}, l = e.length;
    if('number' == typeof l) {
    for(var i = 0; i < l; ++i) {if(e.id == n) {return e;}}
    } else if(e.id == n) {return e;}
    return null;
    }
    : function() {return null;},

    It creates a function, getRefById, that will attempt to obtain a function
    reference when given the id of an element. Once you have that reference,
    you check that the style object is available, and if so, use it.

    function Pop(name) {
    /* Try to get the element identified as name. */
    var e = getRefById(name), s;
    /* If a reference was obtained... */
    if(e) {
    /* ...check for the style property. */
    if(e.style) {
    s = e.style;
    } else {
    /* If it doesn't exist, use the element itself. */
    s = e;
    }
    s.visibility = 'visible';
    }
    }

    This can be reduced to:

    function Pop(name) {
    var e = getRefById(name);
    if(e) {(e.style || e).visibility = 'visible';}
    }

    The main difference is the use of the logical OR operator, '||'. Rather
    than operating on booleans only, it evaluates the 'trueness' of the
    operands. If the first operand evaluates to true, its value (the style
    object in this case) is the result. If the first operand evaluates to
    false, the second value is always returned.

    > }
    > function Wop(name){
    > eval("document.all."+name+".style.visibility='hidden'");
    > }


    The above obviously applies here, too.

    [snip]

    > <div id="prod"
    > Style="background-color:#ff0000;Position:Absolute;Left:39px;
    > Top:89px;Width:178px;Height:16px;Visibility:visible;z-index:31"


    Why this massive amount inline style information? Comparing it to the DIV
    below, only the z-index and the visibility property seem to be different.
    Move it into a style sheet and use a class selector. The remaining unique
    information can be applied with an id selector.

    [snip]

    > <table width="178" height="16" border="0" cellspacing="0"
    > cellpadding="0" class="menu">
    > <tr>
    > <td align="center" valign="middle">Volleyball</td>


    Why use deprecated attributes on the table and cell elements when you're
    already using CSS?

    [snip]

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Oct 9, 2004
    #15
  16. Lasse Reichstein Nielsen wrote:
    <snip>
    >> ns6 = (!document.all && document.getElementById);
    >> //ns6 = true if Netscape 6+

    >
    > That also matches Opera 6 (unless identifying as IE) and
    > Opera 5, and possibly also Safari and Konqeror (unless
    > they decided to support document.all as well).

    <snip>

    Safari and Konqueror do implement - document.all -, so like NetFront,
    IceBrowser and Opera 7 (and sometimes 5-6), they will be identified as
    IE 5+.

    Richard.
     
    Richard Cornford, Oct 9, 2004
    #16
  17. George Hester wrote:
    <snip>
    > No as I explained earlier. I'm just that much of a
    > clicker on the Net. The reason being I have been
    > burned too often.

    <snip>

    At least one of the links form quick answer 26 in the FAQ is to another
    page on jibbering.com, so if it is considered safe to view the FAQ in
    HTML form (and it is (Currently no FAQ or FAQ notes pages attempt to
    execute any script at all)) then it should also be considered safe to
    view that page. Though, even when using IE, disabling scripting and
    ActiveX should eliminate any risk.

    Richard.
     
    Richard Cornford, Oct 9, 2004
    #17
  18. Thank you for your comprehensive answer.

    <snip>
    > The use of the - eval - contributes nothing to simplicity here, in the
    > source code or the execution of the code. It follows from nothing but
    > the author's ignorance of javascript as a language...


    You've got me there.

    I learned html when it was still static and I am desperately trying to keep
    up with the hectic pace of all the changes.

    Reading your reply, I realise that I am only using snipets of things I've
    read all over the place, copying javascript code that does what I need
    without really understanding it and using CSS only for text attributes where
    I should have used it for more.

    Consequently I see now that my code is quite ugly, a bastardisation of old
    and new programming. I will take your comments to heart and try to clean it.

    Thanks again to you (and all the others) for taking the time for your
    detailed reply.


    Roger
     
    Roger Desparois, Oct 10, 2004
    #18
  19. Roger Desparois

    Mark Preston Guest

    Michael Winter wrote:

    > On Sat, 9 Oct 2004 09:33:05 -0400, Roger Desparois
    > <> wrote:
    >
    > [snip]
    >
    >> NS won't recognize it.
    >>
    >> Can anyone tell me why ?

    >
    > The document.all collection is a Microsoft invention, support by only a
    > few other browsers.
    >

    Please note that the PR version of the final Firefox will also support
    "document.all" for compatibility with poorly written code. Not, I feel,
    a good idea but certainly an understandable move.
     
    Mark Preston, Oct 11, 2004
    #19
  20. Roger Desparois

    VK Guest

    > Netscape 4 is this:
    >
    > ns4 = (document.layers);
    > //ns4 = true if Netscape 4


    Of course it is totally ancient history by now, so just in respect to the
    Great_Olds (meaning NN4x series :)
    :
    document.layers was a collection of all layers on the given page. So the
    call document.layers gives you the length of this collection. Usually at
    least one layer was presented, so it casted nicely to true. But without any
    layers it gave you false (0 -> false).
    That was the rare case then it was better to use navigator.userAgent and
    parseFloat to get the particular build.
    I believe by 4.72 they fixed it so document.layers <> document.layers.length
    (default property call), but nobody cared too much at that time anyway.
     
    VK, Oct 11, 2004
    #20
    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:
    648
    [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:
    688
    Ashwini Khanna
    Jan 20, 2005
  3. Federico Bari
    Replies:
    3
    Views:
    452
    Mark Parnell
    Sep 5, 2003
  4. Ruskin
    Replies:
    2
    Views:
    154
    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:
    130
    Federico Bari
    Sep 6, 2003
Loading...

Share This Page