JavaScript Window Navigator

Back to JS page

Table of Contents

The Navigator Object

The window.navigator object contains information about the visitor's browser. It can be used to detect browser properties like cookies enabled, language, platform, and user agent.

Browser Cookies

The navigator.cookieEnabled property returns true if cookies are enabled in the browser:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Navigator</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Browser Cookies</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "navigator.cookieEnabled: " + navigator.cookieEnabled;
</script>

</body>
</html>

Example 1

Result View Example

The Browser Language

The navigator.language property returns the browser's language:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Navigator</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>The Browser Language</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "navigator.language: " + navigator.language;
</script>

</body>
</html>

Example 2

Result View Example

Is The Browser Online?

The navigator.onLine property returns true if the browser is online:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Navigator</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Is The Browser Online?</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "navigator.onLine: " + navigator.onLine;
</script>

</body>
</html>

Example 3

Result View Example

The Browser Agent

The navigator.userAgent property returns the user-agent string sent by the browser:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Navigator</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>The Browser Agent</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "navigator.userAgent: " + navigator.userAgent;
</script>

</body>
</html>

Example 4

Result View Example

The Browser Platform

The navigator.platform property returns the browser platform (operating system):

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Navigator</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>The Browser Platform</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "navigator.platform: " + navigator.platform + "<br><br>" +
  "All navigator properties:<br>" +
  "cookieEnabled: " + navigator.cookieEnabled + "<br>" +
  "language: " + navigator.language + "<br>" +
  "onLine: " + navigator.onLine + "<br>" +
  "platform: " + navigator.platform + "<br>" +
  "appName: " + navigator.appName + "<br>" +
  "appVersion: " + navigator.appVersion + "<br>" +
  "userAgent: " + navigator.userAgent + "<br>" +
  "product: " + navigator.product + "<br>" +
  "appCodeName: " + navigator.appCodeName + "<br>" +
  "javaEnabled: " + navigator.javaEnabled();
</script>

</body>
</html>

Example 5

Result View Example

Document

Document in project

You can Download PDF file.

Reference