Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript Window Navigator


May 06, 2021 JavaScript


Table of contents


JavaScript Window Navigator


The window.navigator object contains information about the visitor's browser.


Window Navigator

The window.navigator object is written without the prefix window.

<div id="example"></div>

<script>

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";

document.getElementById("example").innerHTML=txt;

</script>

Try it out . . .


Warning!!!

Information from navigator objects is misleading and should not be used to detect browser versions because:

  • Navigator data can be changed by the browser user
  • Some browsers recognize errors on the test site
  • The browser could not report a new operating system that was released later than the browser

Browser detection

Because navigator can mislead browser detection, object detection can be used to sniff different browsers.

Because different browsers support different objects, you can use objects to detect browsers. For example, because only Opera supports the property "window.opera," you can identify Opera accordingly.

Example: if (window.opera) some action...}


Read about it

Check out our javaScript Navigator object reference manual, which provides all the properties and methods of the Navigator object.

This manual contains detailed descriptions and examples of how each property and method is used.