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

J

Jake

Hi all

I am trying to read all the navigator object elements

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

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

Anyone can help me a bit? Thanks
 
G

Grant Wagner

Jake said:
Hi all

I am trying to read all the navigator object elements

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

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

Anyone can help me a bit? Thanks


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

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
J

Jake

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

Thanks Grant works great
now I need to figure out when typeof returns object, which I know hides some values too :)
 
J

Jake

Hi kaeli,
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.

Thanks
Great help :)
 
G

Grant Wagner

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

Thanks Grant works great
now I need to figure out when typeof returns object, which I know hides some values too :)

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()).nodeType); works fine in Firefox 0.9, but: alert((new
Image()).textContent); throws an exception, even though "textContent" is a valid property for
the Image object. So any "for (... in ...)" display of Image properties needs to specifically
exclude "textContent" on Firefox 0.9 (and most likely other Gecko-based browsers).

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
J

Jake

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

And this is what I brew of it :)

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

<body>
<script language="javascript">
// document.write(navigator.plugins.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 programmatically 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.
 
J

Jake

Hi Robert,
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 programmatically 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.

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;&nbsp;"
+ i +' : '
+' ('
+ typeof p
+ ') '
+ p );
}
catch(e)
{
document.write("... Error writing out structure. Was " +
p + " of " + i);
}

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

}
</script>
</head>

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


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
http://jake98.no-ip.info
Best Regards
Jake
 
J

Jake

Hi Robert,
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?

IE 6.0.2800.1106
Windows 98 Second Edition 4.10.2222 A
Do you know what line of code is failing?

Navigator typeof object = not supported

Thanks Robert

--
Replies in the same thread please
Windows 98 links to solutions
http://jake98.no-ip.info
Best Regards
Jake
 
R

Richard Cornford

Jake wrote:
Navigator typeof object = not supported

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

Richard.
 
J

Jake

Hi Richard,

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

<!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;&nbsp;"
+ i +' : '
+' ('
+ typeof p
+ ') '
+ p );
}
catch(e)
{
document.write("... Error writing out structure. Was " +
p + " of " + i);
}

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

}
</script>
</head>

<body>
<script type="text/javascript">
// document.write(navigator.plugins.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
http://jake98.no-ip.info
Best Regards
Jake
 
R

Robert

Jake said:
Hi Richard,

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

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;&nbsp;"
+ i +' : '
+' ('
+ typeof p
+ ') '
+ p );
}
catch(e) {
document.write("... Error writing out structure. Was " +
p + " of " + i);
}

if (typeof p == 'object') {
document.write("<br>[] i = " + i);
show(p);
}
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.plugins.length);
show(navigator);
//document.write("<br><br><br>Show the document<br>");
// show(document);
</script>
</body>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top