Navigator object : how do I get all the inside elements?

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

    #1

    Navigator object : how do I get all the inside elements?

    Hi all

    I am trying to read all the navigator object elements

    1. Using the navigator.lengt h returns undefined, cant use for loop;

    2.Using and array of known elements like
    var a = Array("appCodeN ame","appName", "appVersion ");
    I seem to miss something to get it combined like navigator.a[i]

    Anyone can help me a bit? Thanks

    --
    Windows98 links to solutions http://jake98.no-ip.info
    Replies in the same thread please
    Regards Jake
  • kaeli

    #2
    Re: Navigator object : how do I get all the inside elements?

    In article <n1hAc.351$jQ4. 113984632@hebe. telenet-ops.be>, me@home.com
    enlightened us with...[color=blue]
    > Hi all
    >
    > I am trying to read all the navigator object elements
    >[/color]

    Why?
    It rarely does anything useful.

    If you're trying to do browser detection, it's worthless.
    If you're trying to do plugin detection, I believe there's a better way
    for that, too, but I'd have to go look it up.

    --
    --
    ~kaeli~
    Contrary to popular opinion, the plural of 'anecdote' is
    not 'fact'.



    Comment

    • Grant Wagner

      #3
      Re: Navigator object : how do I get all the inside elements?

      Jake wrote:
      [color=blue]
      > Hi all
      >
      > I am trying to read all the navigator object elements
      >
      > 1. Using the navigator.lengt h returns undefined, cant use for loop;
      >
      > 2.Using and array of known elements like
      > var a = Array("appCodeN ame","appName", "appVersion ");
      > I seem to miss something to get it combined like navigator.a[i]
      >
      > Anyone can help me a bit? Thanks[/color]

      for (var prop in navigator) {
      document.write(
      prop + ' = ' + navigator[prop] +
      ' (' + typeof navigator[prop] + ')' +
      '<br>'
      );
      }

      --
      | Grant Wagner <gwagner@agrico reunited.com>

      * Client-side Javascript and Netscape 4 DOM Reference available at:
      *


      * 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


      Comment

      • Jake

        #4
        Re: Navigator object : how do I get all the inside elements?


        Hi Grant Wagner,
        [color=blue]
        > for (var prop in navigator) {
        > document.write(
        > prop + ' = ' + navigator[prop] +
        > ' (' + typeof navigator[prop] + ')' +
        > '<br>'
        > );
        > }[/color]

        Thanks Grant works great
        now I need to figure out when typeof returns object, which I know hides some values too :)
        --
        Windows98 links to solutions http://jake98.no-ip.info
        Replies in the same thread please
        Regards Jake

        Comment

        • Jake

          #5
          Re: Navigator object : how do I get all the inside elements?


          Hi kaeli,
          [color=blue]
          > Why?
          > It rarely does anything useful.
          >
          > If you're trying to do browser detection, it's worthless.
          > If you're trying to do plugin detection, I believe there's a better way
          > for that, too, but I'd have to go look it up.[/color]

          Thanks
          Great help :)
          --
          Windows98 links to solutions http://jake98.no-ip.info
          Replies in the same thread please
          Regards Jake

          Comment

          • Grant Wagner

            #6
            Re: Navigator object : how do I get all the inside elements?

            Jake wrote:
            [color=blue]
            > Hi Grant Wagner,
            >[color=green]
            > > for (var prop in navigator) {
            > > document.write(
            > > prop + ' = ' + navigator[prop] +
            > > ' (' + typeof navigator[prop] + ')' +
            > > '<br>'
            > > );
            > > }[/color]
            >
            > Thanks Grant works great
            > now I need to figure out when typeof returns object, which I know hides some values too :)[/color]

            Modify the function to call itself recursively with "obj[prop]" if "typeof obj[prop] ==
            'object'". Note that this is filled with all sorts of pitfalls. Lots of user agents generate
            errors from simply trying to _test_ "typeof object[property]" for specific properties of
            specific (usually host) objects.

            For example: alert((new Image()).nodeTy pe); works fine in Firefox 0.9, but: alert((new
            Image()).textCo ntent); throws an exception, even though "textConten t" is a valid property for
            the Image object. So any "for (... in ...)" display of Image properties needs to specifically
            exclude "textConten t" on Firefox 0.9 (and most likely other Gecko-based browsers).

            --
            | Grant Wagner <gwagner@agrico reunited.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


            Comment

            • Jake

              #7
              Re: Navigator object : how do I get all the inside elements?

              Hi Grant Wagner,

              Thanks for replying
              As you may notice I am fairly new at javascript
              although i have some background from other languages
              I fully appreciate your help
              You advised :
              [color=blue]
              > Modify the function to call itself recursively with "obj[prop]" if "typeof obj[prop] ==
              > 'object'". Note that this is filled with all sorts of pitfalls. Lots of user agents generate
              > errors from simply trying to _test_ "typeof object[property]" for specific properties of
              > specific (usually host) objects.[/color]

              And this is what I brew of it :)

              <HEAD>
              <script language="javas cript">
              function show(p) {
              document.write( 'parm = ' + p + '<br>');
              for (i in p) {
              document.write(
              i +' : '
              +' ('
              + typeof p[i]
              + ') '
              + p[i] );
              if (typeof p[i] == 'object') {
              // show(p[i]);
              }
              document.write( '<br>');
              }
              }
              </script>
              </head>

              <body>
              <script language="javas cript">
              // document.write( navigator.plugi ns.length);
              show(navigator) ;
              </script>
              </body>

              A few questions:
              1. first line in function, to debug should display the calling parameter? says parm = without a value, crlf is executed
              2. when i uncomment the recursive line caller i get a second parm = , so the function calls itself, and stops
              the error is object doesnt support this property or method
              2a. how can i know programmaticall y what is supported?
              2b. is there some sort of error trap so the rest of the function can continue to display the (working) rest?
              3. Is it possible to bump the array into a new array with numeric indexes?
              If so, the .length of each item would be available which would make things easier
              Again, thanks for your time and effort.
              --
              Windows98 links to solutions http://jake98.no-ip.info
              Replies in the same thread please
              Best Regards
              Jake

              Comment

              • Robert

                #8
                Re: Navigator object : how do I get all the inside elements?

                In article <4ZIAc.914$US5. 267299979@hesti a.telenet-ops.be>,
                "Jake" <me@home.com> wrote:
                [color=blue]
                >
                > A few questions:
                > 1. first line in function, to debug should display the calling parameter?
                > says parm = without a value, crlf is executed
                > 2. when i uncomment the recursive line caller i get a second parm = , so the
                > function calls itself, and stops
                > the error is object doesnt support this property or method
                > 2a. how can i know programmaticall y what is supported?
                > 2b. is there some sort of error trap so the rest of the function can continue
                > to display the (working) rest?
                > 3. Is it possible to bump the array into a new array with numeric indexes?
                > If so, the .length of each item would be available which would make things
                > easier
                > Again, thanks for your time and effort.[/color]

                Thanks Jake I made a few additions to your code. See that addition of
                var before the i. Without the var, i is a global variable. ( I left
                out the var i in my object debug routine once too. )

                For some reason, IE managed to come up with an error in for (var i in p)
                when I did this. Do not know how. I added the try statement. I assume
                this was causing the problem, but I now think it was the var i.

                I know the differences in style. I copied some stuff.

                I tired this in IE 5.2 for MacOS. I didn't try the posted version in
                Netscape 7.1, but an earlier version took forever to run.

                Robert

                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
                <HEAD>
                <script type="text/javascript">
                function show(p) {
                document.write( '<br>parm = ' + p + '<br>');
                for (var i in p) {

                try
                {
                document.write(
                "&nbsp;&nbs p;"
                + i +' : '
                +' ('
                + typeof p[i]
                + ') '
                + p[i] );
                }
                catch(e)
                {
                document.write( "... Error writing out structure. Was " +
                p + " of " + i);
                }

                if (typeof p[i] == 'object') {
                show(p[i]);
                }
                else {
                document.write( '<br>');
                }
                }

                }
                </script>
                </head>

                <body>
                <script type="text/javascript">
                // document.write( navigator.plugi ns.length);
                show(navigator) ;
                document.write( "<br>Show the document<br>");
                show(document);
                </script>
                </body>

                Comment

                • Jake

                  #9
                  Re: Navigator object : how do I get all the inside elements?


                  Hi Robert,
                  [color=blue][color=green]
                  > >
                  > > A few questions:
                  > > 1. first line in function, to debug should display the calling parameter?
                  > > says parm = without a value, crlf is executed
                  > > 2. when i uncomment the recursive line caller i get a second parm = , so the
                  > > function calls itself, and stops
                  > > the error is object doesnt support this property or method
                  > > 2a. how can i know programmaticall y what is supported?
                  > > 2b. is there some sort of error trap so the rest of the function can continue
                  > > to display the (working) rest?
                  > > 3. Is it possible to bump the array into a new array with numeric indexes?
                  > > If so, the .length of each item would be available which would make things
                  > > easier
                  > > Again, thanks for your time and effort.[/color]
                  >
                  > Thanks Jake I made a few additions to your code. See that addition of
                  > var before the i. Without the var, i is a global variable. ( I left
                  > out the var i in my object debug routine once too. )
                  >
                  > For some reason, IE managed to come up with an error in for (var i in p)
                  > when I did this. Do not know how. I added the try statement. I assume
                  > this was causing the problem, but I now think it was the var i.
                  >
                  > I know the differences in style. I copied some stuff.
                  >
                  > I tired this in IE 5.2 for MacOS. I didn't try the posted version in
                  > Netscape 7.1, but an earlier version took forever to run.
                  >
                  > Robert
                  >
                  > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
                  > <HEAD>
                  > <script type="text/javascript">
                  > function show(p) {
                  > document.write( '<br>parm = ' + p + '<br>');
                  > for (var i in p) {
                  >
                  > try
                  > {
                  > document.write(
                  > "&nbsp;&nbs p;"
                  > + i +' : '
                  > +' ('
                  > + typeof p[i]
                  > + ') '
                  > + p[i] );
                  > }
                  > catch(e)
                  > {
                  > document.write( "... Error writing out structure. Was " +
                  > p + " of " + i);
                  > }
                  >
                  > if (typeof p[i] == 'object') {
                  > show(p[i]);
                  > }
                  > else {
                  > document.write( '<br>');
                  > }
                  > }
                  >
                  > }
                  > </script>
                  > </head>
                  >
                  > <body>
                  > <script type="text/javascript">
                  > // document.write( navigator.plugi ns.length);
                  > show(navigator) ;
                  > document.write( "<br>Show the document<br>");
                  > show(document);
                  > </script>
                  > </body>[/color]

                  I have added you suggestion to the script and
                  The results:

                  with show(document) aborts because not enough memory
                  I can understand that since document contains a bunch of properties

                  with show(navigator) I still have the same error 'object does not support this type of property'

                  The questions at top still remain
                  Thanks for your effort
                  --
                  Replies in the same thread please
                  Windows 98 links to solutions

                  Best Regards
                  Jake

                  Comment

                  • Robert

                    #10
                    Re: Navigator object : how do I get all the inside elements?

                    In article <%qlBc.1154$5X2 .312809571@hest ia.telenet-ops.be>,
                    "Jake" <me@home.com> wrote:
                    [color=blue]
                    > I have added you suggestion to the script and
                    > The results:
                    >
                    > with show(document) aborts because not enough memory
                    > I can understand that since document contains a bunch of properties
                    >
                    > with show(navigator) I still have the same error 'object does not support
                    > this type of property'
                    >
                    > The questions at top still remain
                    > Thanks for your effort[/color]

                    I may have missed this info, what Operating System and what version of
                    the Operating System are you using? What web browser and version of the
                    web browser are you using?

                    Do you know what line of code is failing?

                    Robert

                    Comment

                    • Jake

                      #11
                      Re: Navigator object : how do I get all the inside elements?


                      Hi Robert,
                      [color=blue]
                      > I may have missed this info, what Operating System and what version of
                      > the Operating System are you using? What web browser and version of the
                      > web browser are you using?[/color]

                      IE 6.0.2800.1106
                      Windows 98 Second Edition 4.10.2222 A
                      [color=blue]
                      >
                      > Do you know what line of code is failing?[/color]

                      Navigator typeof object = not supported

                      Thanks Robert

                      --
                      Replies in the same thread please
                      Windows 98 links to solutions

                      Best Regards
                      Jake

                      Comment

                      • Richard Cornford

                        #12
                        Re: Navigator object : how do I get all the inside elements?

                        Jake wrote:
                        <snip>[color=blue][color=green]
                        >> Do you know what line of code is failing?[/color]
                        >
                        > Navigator typeof object = not supported[/color]

                        Either that isn't a line of code at all, or it is so generally erroneous
                        that it should be expected to fail.

                        Richard.


                        Comment

                        • Jake

                          #13
                          Re: Navigator object : how do I get all the inside elements?

                          Hi Richard,

                          This thread has been going for a while, so here is the function
                          It gets stuck when the function accesses typeof navigator.plugi ns

                          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
                          <HEAD>
                          <script type="text/javascript">
                          function show(p) {
                          document.write( '<br>parm = ' + p + '<br>');
                          for (var i in p) {

                          try
                          {
                          document.write(
                          "&nbsp;&nbs p;"
                          + i +' : '
                          +' ('
                          + typeof p[i]
                          + ') '
                          + p[i] );
                          }
                          catch(e)
                          {
                          document.write( "... Error writing out structure. Was " +
                          p + " of " + i);
                          }

                          if (typeof p[i] == 'object') {
                          show(p[i]);
                          }
                          else {
                          document.write( '<br>');
                          }
                          }

                          }
                          </script>
                          </head>

                          <body>
                          <script type="text/javascript">
                          // document.write( navigator.plugi ns.length);
                          show(navigator) ;
                          document.write( "<br>Show the document<br>");
                          show(document);
                          </script>
                          </body>

                          --
                          Replies in the same thread please
                          Windows 98 links to solutions

                          Best Regards
                          Jake

                          Comment

                          • Robert

                            #14
                            Re: Navigator object : how do I get all the inside elements?

                            "Jake" <me@home.com> wrote in message news:<NNfCc.200 $%O4.96308268@h ebe.telenet-ops.be>...[color=blue]
                            > Hi Richard,
                            >
                            > This thread has been going for a while, so here is the function
                            > It gets stuck when the function accesses typeof navigator.plugi ns
                            >[/color]

                            For some reason in the Winodows 98 version of IE, the statement for
                            (var i in p) is generating invalid values in variable i. Do not know
                            the story. I have coded up a workaround.

                            For testing javascript programs, I recommend using a Gecko based
                            browser like Netscape 7.1.

                            Example code follows.

                            I have not tried all the error paths.

                            Robert


                            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
                            <HEAD>
                            <script type="text/javascript">
                            function show(p) {
                            document.write( '<br>parm = ' + p + '<br>');
                            document.write( 'typeof p = ' + typeof p + '<br>');
                            if (typeof p == 'object' ) {
                            try {
                            for (var i in p) {
                            try {
                            document.write(
                            "&nbsp;&nbs p;"
                            + i +' : '
                            +' ('
                            + typeof p[i]
                            + ') '
                            + p[i] );
                            }
                            catch(e) {
                            document.write( "... Error writing out structure. Was " +
                            p + " of " + i);
                            }

                            if (typeof p[i] == 'object') {
                            document.write( "<br>[] i = " + i);
                            show(p[i]);
                            }
                            else {
                            document.write( '<br>');
                            }
                            } // of for loop
                            } // of try for for statement
                            catch(e) {
                            document.write( "<br>... for loop control problem. IE seems " +
                            "prone to these problems. e = " + e + "<br>");
                            }
                            } // of is object if
                            else {
                            document.write( "... Error. Function expects an object " +
                            "but didn't get an object.");
                            document.write( 'typeof p = ' + typeof p + '<br>');
                            }

                            } // of function
                            </script>
                            </head>

                            <body>
                            <script type="text/javascript">
                            // document.write( navigator.plugi ns.length);
                            show(navigator) ;
                            //document.write( "<br><br><br>Sh ow the document<br>");
                            // show(document);
                            </script>
                            </body>

                            Comment

                            Working...