Why doesn't this work in Netscape?

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

    Why doesn't this work in Netscape?

    This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE
    but in Netscape 7.2, I get a blank page. Any suggestions?

    Thanks,
    Brett


    <html>
    <head>

    <script language="JavaS cript"><!--
    rowArray = new Array();
    rowArray[1] = '<form>Row 1: <input type="button" value="Reveal"
    onClick="clicke d(2)"><\/form>';
    rowArray[2] = 'This is some text for row 1';
    rowArray[3] = '<form>Row 3: <input type="button" value="Reveal"
    onClick="clicke d(4)"><\/form>';
    rowArray[4] = 'Row 4 when clicked reveals this text';
    rowArray[5] = '<form>Row 5: <input type="button" value="Reveal"
    onClick="clicke d(6)"><\/form>';
    rowArray[6] = 'Contents of the last row';

    viewArray = new Array();
    viewArray[1] = viewArray[3] = viewArray[5] = true;
    viewArray[2] = viewArray[4] = viewArray[6] = false;

    function refreshTable() {

    var output = '<table border="1" width="500">';
    for (var i = 1; i <= rowArray.length ; i++) {
    if (viewArray[i])
    output += '<tr><td>' + rowArray[i] + '<\/td><\/tr>';
    }
    output += '<\/table>';

    if (document.all)
    document.all('m yTable').innerH TML = output;
    else if (document.layer s) {
    document.layers['myTable'].document.open( );
    document.layers['myTable'].document.write ln(output);
    document.layers['myTable'].document.close ();
    }
    }

    function clicked(x) {
    viewArray[x] = !viewArray[x];
    refreshTable();
    }
    //--></script>

    </head>

    <body onLoad="javascr ipt:refreshTabl e();">


    <span id="myTable" style="position :absolute"></span>


    </body>
    </html>


  • Lee

    #2
    Re: Why doesn't this work in Netscape?

    Brett said:[color=blue]
    >
    >This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE
    >but in Netscape 7.2, I get a blank page. Any suggestions?[/color]

    I suggest that you ignore any code examples that are supposed
    to work in Netscape 4 and IE 4.

    That code is completely obsolete.

    Comment

    • Brett

      #3
      Re: Why doesn't this work in Netscape?


      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:ckpn4j02oc l@drn.newsguy.c om...[color=blue]
      > Brett said:[color=green]
      >>
      >>This code is supposed to work in Netscape 4+ and IE 4+. It works fine in
      >>IE
      >>but in Netscape 7.2, I get a blank page. Any suggestions?[/color]
      >
      > I suggest that you ignore any code examples that are supposed
      > to work in Netscape 4 and IE 4.
      >
      > That code is completely obsolete.
      >[/color]
      Ok but why exactly doesn't it work in Netscape 7.2?

      Thanks,
      Brett


      Comment

      • Fred Oz

        #4
        Re: Why doesn't this work in Netscape?

        Brett wrote:
        [snip][color=blue]
        > Ok but why exactly doesn't it work in Netscape 7.2?[/color]

        I'd guess because your logic is that all browsers support either
        document.layers or document.all. That would be wrong - e.g. Safari.

        Feature detection is great, but only if you use it correctly. Safari
        (and I suspect Netscape 7.2) don't support either of the above, they
        expect you to use document.getEle mentById or similar.

        Also, explicitly putting content into arrays is time consuming and makes
        life difficult, consider the code below (with feature detection for
        getElementById) . Watch for line wrapping, I can't manually wrap them
        because of your code design.

        Lastly, this is the craziest way I've seen to hide and show rows.
        What's wrong with simply giving each row an id, then hide/show them by
        modifying the display attribute? A re-write is below your fixed code -
        I think you will find it vastly simpler.

        You can also ditch the "<!-- //-->" junk to hide scripts unless you
        think someone with Netscape 1.0 or Mosaic will use your page.

        Fred.

        Partial fix of original code:

        <html>
        <head>

        <script language="JavaS cript">
        var rowArray = [
        'empty',
        '<form>Row 1: <input type="button" value="Reveal"
        onClick="clicke d(2)"><\/form>',
        'This is some text for row 1',
        '<form>Row 3: <input type="button" value="Reveal"
        onClick="clicke d(4)"><\/form>',
        'Row 4 when clicked reveals this text',
        '<form>Row 5: <input type="button" value="Reveal"
        onClick="clicke d(6)"><\/form>',
        'Contents of the last row',
        ]

        viewArray = new Array();
        viewArray[1] = viewArray[3] = viewArray[5] = true;
        viewArray[2] = viewArray[4] = viewArray[6] = false;

        function refreshTable() {

        var output = '<table border="1" width="500">';
        for (var i = 1; i <= rowArray.length ; i++) {
        if (viewArray[i])
        output += '<tr><td>' + rowArray[i] + '<\/td><\/tr>';
        }
        output += '<\/table>';

        if (document.all) {
        document.all('m yTable').innerH TML = output;
        alert('Using doc.all');
        } else {
        if (document.layer s) {
        alert('Using doc.layers');
        document.layers['myTable'].document.open( );
        document.layers['myTable'].document.write ln(output);
        document.layers['myTable'].document.close ();
        } else {
        if (document.getEl ementById) {
        document. getElementById( 'myTable').inne rHTML = output;
        alert('Using doc.GEBI\n' + output);
        }

        }
        }
        }

        function clicked(x) {
        viewArray[x] = !viewArray[x];
        refreshTable();
        }
        </script>

        </head>

        <body onLoad="javascr ipt:refreshTabl e();">


        <span id="myTable" style="position :absolute"></span>


        </body>
        </html>


        Version using element attributes:

        <html>
        <head><title>Sh ow/Hide Rows</title>

        <script type="text/javascript">
        function showHide(r) {
        if (r.style.displa y == '') {
        r.style.display = 'none';
        } else {
        r.style.display = '';
        }
        }
        </script>
        </head>
        <body>
        <table>
        <tr id="row1">
        <td>Here is cell 1
        <form action="">
        <input type="button" value="show/hide row 2"
        onclick="showHi de(document.get ElementById('ro w2'))"
        </td>
        </tr><tr id="row2">
        <td>Here is cell 2</td>
        </tr>
        </table>
        </body>
        </html>

        Comment

        • Fred Oz

          #5
          Re: Why doesn't this work in Netscape?

          Fred Oz wrote:
          [snip][color=blue]
          >
          > Version using element attributes:
          >[/color]

          Aggghhh! I copied a pasted in two chunks, and of course stuffed it up.
          The code should work but only becaue of browser tolerance, here is the
          corrected code:

          <html>
          <head><title>Sh ow/Hide Rows</title>

          <script type="text/javascript">
          function showHide(r) {
          if (r.style.displa y == '') {
          r.style.display = 'none';
          } else {
          r.style.display = '';
          }
          }
          </script>
          </head>
          <body>
          <table>
          <tr id="row1">
          <td>Here is cell 1
          <form action="">
          <input type="button" value="show/hide row 2"
          onclick="showHi de(document.get ElementById('ro w2'))"[color=blue]
          >[/color]
          </form>
          </td>
          </tr><tr id="row2">
          <td>Here is cell 2</td>
          </tr>
          </table>
          </body>
          </html>

          Comment

          • Mark Preston

            #6
            Re: Why doesn't this work in Netscape?

            Brett wrote:
            [color=blue]
            > This code is supposed to work in Netscape 4+ and IE 4+.[/color]

            No it isn't.
            [color=blue]
            > function refreshTable() {
            >
            >[snip]
            >
            > if (document.all)
            > document.all('m yTable').innerH TML = output;
            > else if (document.layer s) {
            > document.layers['myTable'].document.open( );
            > document.layers['myTable'].document.write ln(output);
            > document.layers['myTable'].document.close ();
            > }
            > }
            >[/color]

            And that is why it isn't.

            "document.a ll" is for MSIE and "document.layer s" is for Netscape 4.
            Everything else is a dead duck.

            Comment

            • Randy Webb

              #7
              Re: Why doesn't this work in Netscape?

              Mark Preston wrote:
              [color=blue]
              > Brett wrote:
              >[color=green]
              >> This code is supposed to work in Netscape 4+ and IE 4+.[/color]
              >
              >
              > No it isn't.[/color]

              If advertised as "IE4+ and Netscape 4+", then yes, its "supposed" to
              work, even if it doesn't work.
              [color=blue][color=green]
              >> function refreshTable() {
              >>
              >> [snip]
              >>
              >> if (document.all)
              >> document.all('m yTable').innerH TML = output;
              >> else if (document.layer s) {
              >> document.layers['myTable'].document.open( );
              >> document.layers['myTable'].document.write ln(output);
              >> document.layers['myTable'].document.close ();
              >> }
              >> }
              >>[/color]
              >
              > And that is why it isn't.
              >
              > "document.a ll" is for MSIE and "document.layer s" is for Netscape 4.[/color]

              No, and No.

              Opera in Spoof mode honors one or the other. Firefox honors
              document.all, and there is even a browser (I don't recall the name, just
              recall Jim Ley mentioning it and Richard Cornford may be able to name
              it) that supports *both* of those.
              [color=blue]
              > Everything else is a dead duck.[/color]

              See above.

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

              Comment

              • Richard Cornford

                #8
                Re: Why doesn't this work in Netscape?

                Randy Webb wrote:[color=blue]
                > Mark Preston wrote:[/color]
                <snip>[color=blue][color=green]
                >> "document.a ll" is for MSIE and "document.layer s" is
                >> for Netscape 4.[/color]
                >
                > No, and No.
                >
                > Opera in Spoof mode honors one or the other. Firefox
                > honors document.all, and there is even a browser (I
                > don't recall the name, just recall Jim Ley mentioning
                > it and Richard Cornford may be able to name it)
                > that supports *both* of those.[/color]
                <snip>

                It was Omniweb

                Richard.


                Comment

                • Mark Preston

                  #9
                  Re: Why doesn't this work in Netscape?

                  Randy Webb wrote:[color=blue]
                  > Mark Preston wrote:
                  >
                  > If advertised as "IE4+ and Netscape 4+", then yes, its "supposed" to
                  > work, even if it doesn't work.
                  >[/color]
                  Don't know about you, but I didn't see any claim from the provider, just
                  from the OP. And as far as I can see it is "supposed" to work in MSIE 4+
                  and Netscape 4 (not "plus").

                  Which was what I pointed out, rather more briefly.
                  [color=blue][color=green]
                  >> "document.a ll" is for MSIE and "document.layer s" is for Netscape 4.[/color]
                  >
                  > No, and No.
                  >[/color]

                  Sorry, but "yes and yes".
                  [color=blue]
                  > Opera in Spoof mode honors one or the other. Firefox honors
                  > document.all, and there is even a browser (I don't recall the name, just
                  > recall Jim Ley mentioning it and Richard Cornford may be able to name
                  > it) that supports *both* of those.
                  >[/color]

                  I know they do - but that is not what they were set up for. The
                  "document.a ll" object was for IE and similarly "document.layer s" was for
                  Netscape 4. It is true, as you said, that other browsers do indeed *use*
                  those forms, but that is not what they were set up for.

                  It is always - almost - best to stick to standards and to avoid this
                  sort of provider-specific code. Granted, in the code referred to it
                  would have been a lot more difficult to do since both were *extensions*
                  to the standard that then existed so that additional features could be
                  used in the specific browsers (and it is because they were extensions
                  that offered additional features that they were "spoofed" in other
                  browsers). But that does not, I'm afarid, alter the point that they are
                  strictly propietary (and in the case of "document.layer s" even version
                  specific) *extensions* to the standard and cannot be relied on.

                  Comment

                  • Randy Webb

                    #10
                    Re: Why doesn't this work in Netscape?

                    Mark Preston wrote:
                    [color=blue]
                    > Randy Webb wrote:
                    >[color=green]
                    >> Mark Preston wrote:[/color][/color]

                    <--snip-->
                    [color=blue][color=green][color=darkred]
                    >>> "document.a ll" is for MSIE and "document.layer s" is for Netscape 4.[/color]
                    >>
                    >>
                    >> No, and No.
                    >>[/color]
                    >
                    > Sorry, but "yes and yes".[/color]

                    The part of my quote that you snipped said this:

                    "All others are dead ducks"

                    And that is patently false, hence my "No, and No.", just as much as
                    saying "document.a ll is for MSIE" is patently false. To me that says its
                    for MSIE only, when its not. And for years the assumption by people that
                    didn't know any different was something along these lines:

                    if (document.all){
                    //its IE
                    }

                    And that is definitely wrong. While document.all was first implemented
                    by MSIE and document.layers in NS4, it does not make them for those
                    browsers alone. Maybe its just the way we interpret what we read *shrug*.
                    [color=blue][color=green]
                    >> Opera in Spoof mode honors one or the other. Firefox honors
                    >> document.all, and there is even a browser (I don't recall the name,
                    >> just recall Jim Ley mentioning it and Richard Cornford may be able to
                    >> name it) that supports *both* of those.
                    >>[/color]
                    >
                    > I know they do - but that is not what they were set up for. The
                    > "document.a ll" object was for IE and similarly "document.layer s" was for
                    > Netscape 4. It is true, as you said, that other browsers do indeed *use*
                    > those forms, but that is not what they were set up for.[/color]

                    That is true, and I agree. But to say, now, that document.all is IE only
                    and document.layers is NS4 only is just plain wrong. Irrelevant of what
                    they were originally intended for.
                    [color=blue]
                    > It is always - almost - best to stick to standards and to avoid this
                    > sort of provider-specific code.[/color]

                    That depends on the standard and how well it's implemented. But then, I
                    am not a big fan of "standards" as I am a fan of whats reality.
                    Standards (with regards to ECMA) is how things *should* be, not how
                    things *are*. .toFixed() being probably the simplest and easiest to
                    screw up yet MS did it. So, do you stick to the "standard", or, do you
                    make it work around the limitation in the flaw of MS' implementation of it?

                    [color=blue]
                    > Granted, in the code referred to it would have been a lot more difficult
                    > to do since both were *extensions* to the standard that then existed so
                    > that additional features could be used in the specific browsers (and it
                    > is because they were extensions that offered additional features that
                    > they were "spoofed" in other browsers).[/color]

                    That code is *very* simple to make work in "modern" browsers using
                    document.getEle mentById, and quite trivially at that. Either way, it
                    doesn't change the simple reality that document.all is not IE4+ and
                    document.layers is not NS4 (exclusively).

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

                    Comment

                    • Mark Preston

                      #11
                      Re: Why doesn't this work in Netscape?

                      Randy Webb wrote:
                      [color=blue]
                      > "All others are dead ducks"
                      >
                      > And that is patently false, hence my "No, and No.", just as much as
                      > saying "document.a ll is for MSIE" is patently false. To me that says its
                      > for MSIE only, when its not. And for years the assumption by people that
                      > didn't know any different was something along these lines:[/color]

                      I tend to keep answers short and simple. That is (usually) why people
                      ask short and simple questions. Yes, as I said, others will *use* them
                      but that it not what they were created *for*, which was what I
                      addressed. Your assumption is reasonable and true, but is neither what I
                      said nor what I inteded to say.
                      [color=blue]
                      > That code is *very* simple to make work in "modern" browsers using
                      > document.getEle mentById, and quite trivially at that.[/color]

                      I agree again.

                      Comment

                      Working...