Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigator Object in javascript. How to determine all properties [duplicate]

Tags:

javascript

Possible Duplicate:
How do I enumerate the properties of a javascript object?

Good day!

I want to determine all the properties of my navigator using javascript by doing this 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 my str variable prints as it is. What i need is the actual value of the property.

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

Thank you in advance.

like image 986
newbie Avatar asked Aug 18 '11 02:08

newbie


People also ask

Which of the following navigator object properties is the same?

1 Answer. The explanation is: The property navigator. appCodeName is the same in both Netscape and IE. The appCodeName property returns the code name of the browser.

Which method is the way to see all the properties of a specified JavaScript object in the console?

The method console. dir() displays an interactive list of the properties of the specified JavaScript object.

Which are the different ways to enumerate all properties of an object in JavaScript?

Every property in JavaScript objects can be classified by three factors: Enumerable or non-enumerable; String or symbol; Own property or inherited property from the prototype chain.


1 Answers

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

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

You could also benefit from dropping document.write(), it's rarely the best way to modify the DOM.

like image 128
alex Avatar answered Nov 09 '22 13:11

alex