JavaScript Window Navigator

In this chapter you will learn about JavaScript Window Navigator object. We can use the navigator object to get the browser related information.

Window Navigator Object

It is not mandatory to put window object before the navigator object. You can access navigator object without the window object.

Check Cookie enabled

The navigator object cookieEnabled property returns true if cookies are enabled on the client browser, otherwise it will return false.

Example

<!DOCTYPE html>
<html>
<body>

Window Navigator object is used to check if browser accepts cookies or not.
<p id="test"></p>

<script>
var ce = (navigator.cookieEnabled) ? 'Enabled' : 'disabled';
document.getElementById("test").innerHTML = "Cookies is " + ce;
</script>

</body>
</html>

Download the code Run the code

Browser Name

Navigator object appName and appCodeName properties returns name of the browser.

<!DOCTYPE html>
<html>
<body>

appName and appCodeName properties returns browser app name and code name.
<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your Browser app name is " + navigator.appName + ' and code name is ' + navigator.appCodeName;
</script>

</body>
</html>

Download the code Run the code

Note

IE11, Chrome, Firefox, and Safari browsers return “Netscape” as appName value.
Chrome, Firefox, IE, Safari, and Opera browsers return “Mozilla” as appCodeName value.

Browser Engine

Navigator object product property returns engine name of the browser.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your browser engine is " + navigator.product;
</script>

</body>
</html>

Download the code Run the code

Browser Version

Navigator object appVersion property returns browser version information.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your Browser version is " + navigator.appVersion;
</script>

</body>
</html>

Download the code Run the code

userAgent property also returns browser information.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your Browser version is " + navigator.userAgent;
</script>

</body>
</html>

Download the code Run the code

The information retrieved from the navigator object can be misleading, and should be avoided to detect browser versions because:

  • Different browsers might have same browser names. For example IE11, Chrome has same name.
  • Navigator data can be changed by external extensions.

Browser Platform

Navigator object platform property returns browser operating system.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your Browser running on " + navigator.platform;
</script>

</body>
</html>

Download the code Run the code

Browser Language

Navigator object language property returns browser’s language.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = "Your Browser language is " + navigator.language;
</script>

</body>
</html>

Download the code Run the code

Java Enabled?

Navigator object javaEnabled() methods returns if Java is enabled or not.

<!DOCTYPE html>
<html>
<body>

<p id="test"></p>

<script>
if(navigator.javaEnabled()) {
    document.getElementById("test").innerHTML = "Java is enabled on your Browser.";
} else {
    document.getElementById("test").innerHTML = "Java is disabled on your Browser.";
}

</script>

</body>
</html>

Download the code Run the code

Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .