Jump to content

Looping Through Navigator Object


Don E

Recommended Posts

Hello everyone, I'm looking at the navigator object in the browser object model and I would like to loop through all the properties and then display the value for each property and output it in a div but I'm not able to get the value for the property to display in the browser.

<!doctype html><html><head><title>Navigator Object</title><script type="text/javascript">function getNav(){document.getElementById('button').style.display = "none";var div = document.getElementById('prop');var output = "";for(property in navigator){  str="navigator"+"."+ property;  output += "<b>" + property + "</b> = <em>" +str+ "</em><br />"; }div.innerHTML = output;}</script></head><body><button id="button" type="button" onclick="getNav();">Get Nav Info</button><div id="prop"></div></body></html>

According to this JavaScript book I have, the method above is suppose to work. The only difference with the book is the author has it run when the page loads and uses document.write to out the info, but the strange thing is... even when following the authors exact way, it still doesn't work for some reason. Book version:

<html><head><title>Navigator Object</title></head><body><big><script type="text/javascript">for(var property in navigator){str="navigator"+"."+ property;document.write(property+ "  <em>"+str+"</em><br />");}</script></big></body></html>

Thanks.

Link to comment
Share on other sites

No wasn't getting any errors. Removing

str="navigator"+"."+ property;

and adding this:

output +=  "<b>" + property + "</b> = <em>" + navigator[property] + "</em><br/>";

... gets the results I was aiming for. Thanks Fox.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...