Window Navigator In JavaScript

Introduction

 
The window.navigator object contains information about the visitor's browser. It can also tell you if cookies and Java are enabled by the user. One of the more interesting properties is the user agent string. This information is sent to every web server. But the user agent string can't be trusted for many web browsers because it can be changed by the user.
 
The following example shows information about the visitor's browser using the window navigator in JavaScript.
 
Complete Program
 
Window_Navigator_Demo.html
  1. <!DOCTYPE html>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title></title>  
  5. </head>  
  6. <body>  
  7. <div id="show" style="color:green"></div>  
  8. <script>  
  9.     lbltxt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";  
  10.     lbltxt += "<p>Browser Name: " + navigator.appName + "</p>";  
  11.     lbltxt += "<p>Browser Version: " + navigator.appVersion + "</p>";  
  12.     lbltxt += "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";  
  13.     lbltxt += "<p>Platform: " + navigator.platform + "</p>";  
  14.     lbltxt += "<p>User-agent header: " + navigator.userAgent + "</p>";  
  15.     lbltxt += "<p>User-agent language: " + navigator.systemLanguage + "</p>";  
  16.     document.getElementById("show").innerHTML = lbltxt;  
  17. </script>  
  18. </body>  
  19. </html> 
Output
 
window-navigator.jpg
 
For more information, download the attached sample application.