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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

</head>

<body>

<div id="show" style="color:green"></div>

<script>

    lbltxt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";

    lbltxt += "<p>Browser Name: " + navigator.appName + "</p>";

    lbltxt += "<p>Browser Version: " + navigator.appVersion + "</p>";

    lbltxt += "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";

    lbltxt += "<p>Platform: " + navigator.platform + "</p>";

    lbltxt += "<p>User-agent header: " + navigator.userAgent + "</p>";

    lbltxt += "<p>User-agent language: " + navigator.systemLanguage + "</p>";

    document.getElementById("show").innerHTML = lbltxt;

</script>

</body>

</html>


Output


window-navigator.jpg

For more information, download the attached sample application.

Up Next
    Ebook Download
    View all
    Learn
    View all