Netscape compatibility

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Winter

    #16
    Re: Netscape compatibility

    On Sat, 9 Oct 2004 09:33:05 -0400, Roger Desparois
    <roger.desparoi s@sympatico.ca> wrote:

    [snip]
    [color=blue]
    > NS won't recognize it.
    >
    > Can anyone tell me why ?[/color]

    The document.all collection is a Microsoft invention, support by only a
    few other browsers.
    [color=blue]
    > And is there a way around the problem ?[/color]

    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.c om/faq/faq_notes/not_browser_det ect.html#bdGEID >
    [color=blue]
    > I really like the elegance of this code and would like to keep using it.[/color]

    I'm afraid that a lack of feature testing and unnecessary use of eval is
    not elegant.
    [color=blue]
    > <head
    > <script language="Javas cript"`>[/color]

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

    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    Script hiding is another obsolete practice, unnecessary for the Web today.
    Remove the SGML comments.
    [color=blue]
    > function Pop(name){
    > eval("document. all."+name+".st yle.visibility= 'visible'");[/color]

    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.c om/faq/faq_notes/square_brackets .html>).

    document.all[name].style.visibili ty = '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.getEle mentById ?
    function(n) {return document.getEle mentById(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[i].id == n) {return e[i];}}
    } 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.
    [color=blue]
    > }
    > function Wop(name){
    > eval("document. all."+name+".st yle.visibility= 'hidden'");
    > }[/color]

    The above obviously applies here, too.

    [snip]
    [color=blue]
    > <div id="prod"
    > Style="backgrou nd-color:#ff0000;P osition:Absolut e;Left:39px;
    > Top:89px;Width: 178px;Height:16 px;Visibility:v isible;z-index:31"[/color]

    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]
    [color=blue]
    > <table width="178" height="16" border="0" cellspacing="0"
    > cellpadding="0" class="menu">
    > <tr>
    > <td align="center" valign="middle" >Volleyball</td>[/color]

    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.

    Comment

    • Richard Cornford

      #17
      Re: Netscape compatibility

      Lasse Reichstein Nielsen wrote:
      <snip>[color=blue][color=green]
      >> ns6 = (!document.all && document.getEle mentById);
      >> //ns6 = true if Netscape 6+[/color]
      >
      > 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).[/color]
      <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.


      Comment

      • Richard Cornford

        #18
        Re: Netscape compatibility

        George Hester wrote:
        <snip>[color=blue]
        > 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.[/color]
        <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.


        Comment

        • Roger Desparois

          #19
          Re: Netscape compatibility

          Thank you for your comprehensive answer.

          <snip>[color=blue]
          > 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...[/color]

          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


          Comment

          • Mark Preston

            #20
            Re: Netscape compatibility

            Michael Winter wrote:
            [color=blue]
            > On Sat, 9 Oct 2004 09:33:05 -0400, Roger Desparois
            > <roger.desparoi s@sympatico.ca> wrote:
            >
            > [snip]
            >[color=green]
            >> NS won't recognize it.
            >>
            >> Can anyone tell me why ?[/color]
            >
            > The document.all collection is a Microsoft invention, support by only a
            > few other browsers.
            >[/color]
            Please note that the PR version of the final Firefox will also support
            "document.a ll" for compatibility with poorly written code. Not, I feel,
            a good idea but certainly an understandable move.

            Comment

            • VK

              #21
              Re: Netscape compatibility

              > Netscape 4 is this:[color=blue]
              >
              > ns4 = (document.layer s);
              > //ns4 = true if Netscape 4[/color]

              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.userA gent 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.


              Comment

              • Dr John Stockton

                #22
                Re: Netscape compatibility

                JRS: In article <ckdudv$ga9$2$8 302bc10@news.de mon.co.uk>, dated Mon, 11
                Oct 2004 13:38:02, seen in news:comp.lang. javascript, Mark Preston
                <usenet@nosourc e.co.uk> posted :
                [color=blue]
                >Please note that the PR version of the final Firefox will also support
                >"document.al l" for compatibility with poorly written code. Not, I feel,
                >a good idea but certainly an understandable move.[/color]

                If document.all is present in addition to document.getEle mentById
                and/or document.layers then ISTM that multi-browser code which tests
                for such entities should be reviewed to see whether the tests are
                correctly prioritised.

                I believe that the code in FAQ 4.15, and the code that was earlier there
                and recognised document.layers , will pass that review.

                My version of that earlier code is probably OK as is, but I see in it
                some commented-out warning code ...

                Perhaps someone could check <URL:http://www.merlyn.demon.co.uk/js-
                date2.htm#RC> in the PR version, just to see whether running text-
                clocks appear.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                • Randy Webb

                  #23
                  Re: Netscape compatibility

                  Dr John Stockton wrote:

                  <--snip-->
                  [color=blue]
                  > Perhaps someone could check <URL:http://www.merlyn.demon.co.uk/js-
                  > date2.htm#RC> in the PR version, just to see whether running text-
                  > clocks appear.[/color]

                  Yes, it appears. The entire section appears the same to me in IE6 SP2 as
                  is it does in Firefox PR


                  --
                  Randy
                  comp.lang.javas cript FAQ - http://jibbering.com/faq

                  Comment

                  • Richard Cornford

                    #24
                    Re: Netscape compatibility

                    "Dr John Stockton" wrote:[color=blue]
                    > Mark Preston posted :[color=green]
                    >> Please note that the PR version of the final Firefox will
                    >> also support "document.a ll" for compatibility with poorly
                    >> written code. Not, I feel, a good idea but certainly an
                    >> understandable move.[/color]
                    >
                    > If document.all is present in addition to
                    > document.getEle mentById and/or document.layers then
                    > ISTM that multi-browser code which tests for such entities
                    > should be reviewed to see whether the tests are correctly
                    > prioritised.[/color]

                    The Mozilla authors have taken the (in my opinion bad, and strange)
                    decision to implement - document.all - such that it is not detectable
                    (by typeof or type-converting) so properly structured feature detecting
                    code will never notice it.

                    If by prioritised you mean which of the various methods should be the
                    preferred choice for element reference retrieval,I would still go with -
                    document.getEle mentById -, not because it is W3C standard but because it
                    is the most well defined, and limited, in the behaviour that should be
                    expected of it. It is possible to add code that will make -
                    document.all - behave exactly like gEID, but emulating all of -
                    document.all - on W3C standard only browsers (are there any of those
                    left now?) is a lot more involved than writing:-

                    document.all = document.getEle mentByTagName{' *');

                    Richard.


                    Comment

                    • Grant Wagner

                      #25
                      Re: Netscape compatibility

                      Richard Cornford wrote:
                      [color=blue]
                      > The Mozilla authors have taken the (in my opinion bad, and strange)
                      > decision to implement - document.all - such that it is not detectable
                      > (by typeof or type-converting) so properly structured feature detecting
                      > code will never notice it.[/color]

                      I am not defending their decision, but I would imagine the Mozilla authors'
                      rational for the - document.all - behaviour to be something akin to:

                      By supporting - document.all - in a way that is not detectable in properly
                      structured feature detecting code, they eliminate the possibility that the
                      less-well-supported document.all path will be chosen. However, if the script
                      is so badly written that it simply assumes document.all will be available,
                      the code (hopefully) won't fail.

                      In other words they want the W3C-compatible path taken when presented with:

                      if (document.all) {
                      // path not taken by FF 1.0PR
                      }
                      if (document.getEl ementById) {
                      // path taken by FF 1.0PR
                      }

                      but they want something like this to work

                      <script language="JavaS cript1.2">
                      <!--
                      // badly written JavaScript here
                      document.all.my Div.style.color = 'Red';
                      //-->
                      </script>

                      Personally I think supporting - document.all - will just perpetuate poorly
                      written code, but I can understand why they have chosen to support it, even
                      in a limited fashion. They have probably simply gotten tired of being told
                      their browser is "broken" because it does not work on the many, many, many
                      poorly authored sites that cater solely to Internet Explorer.

                      --
                      Grant Wagner <gwagner@agrico reunited.com>
                      comp.lang.javas cript FAQ - http://jibbering.com/faq

                      Comment

                      • Richard Cornford

                        #26
                        Re: Netscape compatibility

                        Grant Wagner wrote:[color=blue]
                        > Richard Cornford wrote:[color=green]
                        >> The Mozilla authors have taken the (in my opinion bad, and
                        >> strange) decision to implement - document.all - such that it
                        >> is not detectable (by typeof or type-converting) so properly
                        >> structured feature detecting code will never notice it.[/color]
                        >
                        > I am not defending their decision, but I would imagine the
                        > Mozilla authors' rational for the - document.all - behaviour
                        > to be something akin to:
                        >
                        > By supporting - document.all - in a way that is not detectable
                        > in properly structured feature detecting code, they eliminate
                        > the possibility that the less-well-supported document.all path
                        > will be chosen.[/color]

                        This move makes it questionable as to the extent to which -
                        document.all - is less well supported (at least when all the gecko users
                        have updated). Of the scriptable W3C DOM standard dynamic visual
                        browsers; IE 5+, Opera 7, Konqueror, Safari, Gecko browsers, IceBrowser
                        and probably others, will support - document.all -, along with less
                        dynamic W3C browsers like NetFront and Opera 6 (more or less). And with
                        IE 4 falling into the - document.all - only camp (and probably not being
                        alone there), Mozilla's decision might have swing the numbers away from
                        gEBI.

                        It is a bit like - innerHTML -, it is not DOM standard but it is very
                        well supported and so difficult to justify not using it on the grounds
                        that it is not standard.

                        <snip>[color=blue]
                        > Personally I think supporting - document.all - will just
                        > perpetuate poorly written code, but I can understand why
                        > they have chosen to support it, even in a limited fashion.
                        > They have probably simply gotten tired of being told their
                        > browser is "broken" because it does not work on the many,
                        > many, many poorly authored sites that cater solely to
                        > Internet Explorer.[/color]

                        I agree with your proposed motivation, and that it will perpetuate
                        poorly written code, but I suspect that denying the possibility of
                        detecting an implemented feature will act to undermine feature detecting
                        itself and encourage an attitude of charging in with code that "woks"
                        and never addressing the consequences of its failure.

                        Personally I don't mind whether Mozilla implements it or not, I am not
                        going to prefer to use it because it is more chaotic in its behaviour
                        than gEBI (returning collections sometimes and allowing at least three
                        distinct methods of indexing its contents (at latest on the latest
                        IEs)). But if it is there it should be possible to know that it is
                        there.

                        That would however be near catastrophic because of the:-

                        isNet6Plus = Boolean(documen t.getElementByI d && !document.all);
                        isIE5Plus = Boolean(documen t.getElementByI d && document.all);

                        - style browser detecting that is so (misguidedly) pandemic.

                        In any event the decision appears to have been made so the consequences
                        may eventually become apparent.

                        Richard.


                        Comment

                        • Alexis Nikichine

                          #27
                          Re: Netscape compatibility

                          Richard Cornford wrote:[color=blue]
                          > Grant Wagner wrote:[color=green]
                          >>
                          >>By supporting - document.all - in a way that is not detectable
                          >>in properly structured feature detecting code, they eliminate
                          >>the possibility that the less-well-supported document.all path
                          >>will be chosen.[/color]
                          >
                          >
                          > This move makes it questionable as to the extent to which -
                          > document.all - is less well supported (at least when all the gecko users
                          > have updated). Of the scriptable W3C DOM standard dynamic visual
                          > browsers; IE 5+, Opera 7, Konqueror, Safari, Gecko browsers, IceBrowser
                          > and probably others, will support - document.all -, along with less
                          > dynamic W3C browsers like NetFront and Opera 6 (more or less). And with
                          > IE 4 falling into the - document.all - only camp (and probably not being
                          > alone there), Mozilla's decision might have swing the numbers away from
                          > gEBI.
                          >
                          > It is a bit like - innerHTML -, it is not DOM standard but it is very
                          > well supported and so difficult to justify not using it on the grounds
                          > that it is not standard.[/color]

                          Besides, the 'all' method is not only applicable to the document object,
                          but too any HTML element, too, thus permitting to find an element with a
                          requested ID in only a subtree of the document. I find this useful when
                          generating complex nodes from (DOM, or textual) templates: I needn't
                          care about uniquifying (?) all ID attributes, but at most, only the ID
                          of root template elements.

                          Cheers,

                          Alexis


                          --
                          some domain is free

                          Comment

                          Working...