Navigator object in javascript. How to define all properties

Possible duplicate:
How to list properties of javascript object?

Good day!

I want to determine all the properties of my navigator using javascript by running the following code:

<script type="text/javascript"> for(var property in navigator){ str="navigator."+ property; //HAVING A PROBLEM HERE... document.write(property+ "&nbsp;&nbsp;<em>"+ str+"</em><br />"); } </script> 

But the concatenation of str str prints as is. I need the actual value of the property.

eg. navigator.appCodeName should print mozilla instead of navigator.appCodeName itself.

Thanks in advance.

+7
source share
1 answer

You want to use navigator[property] to access the values ​​assigned to properties.

 for(var property in navigator){ var str = navigator[property] document.write(property+ "&nbsp;&nbsp;<em>"+str+"</em><br />"); } 

You can also use resetting document.write() , this is rarely the best way to change the DOM.

+9
source

All Articles