GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • JS Array Object
  • JS Boolean Object
  • JS Date Object
  • JS Math Object
  • JS Number Object
  • JS String Object
  • JS Reserved Keywords
  • More references

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialrepublic.com — JavaScript Window Navigator - Tutorial Republic

TutorialRepublic
HOME HTML5 CSS3 JAVASCRIPT JQUERY BOOTSTRAP5 v4.6 PHP7 SQL REFERENCES EXAMPLES FAQ SNIPPETS Online HTML Editor
JAVASCRIPT BASIC
JS Introduction JS Getting Started JS Syntax JS Variables JS Generating Output JS Data Types JS Operators JS Events JS Strings JS Numbers JS If…Else JS Switch…Case JS Arrays JS Sorting Arrays JS Loops JS Functions JS Objects
JAVASCRIPT & DOM
JS DOM Nodes JS DOM Selectors JS DOM Styling JS DOM Get Set Attributes JS DOM Manipulation JS DOM Navigation
JAVASCRIPT & BOM
JS Window JS Screen JS Location JS History JS Navigator JS Dialog Boxes JS Timers
JAVASCRIPT ADVANCED
JS Date and Time JS Math Operations JS Type Conversions JS Event Listeners JS Event Propagation JS Borrowing Methods JS Hoisting Behavior JS Closures JS Strict Mode JS JSON Parsing JS Error Handling JS Regular Expressions JS Form Validation JS Cookies JS AJAX Requests JS ES6 Features
JAVASCRIPT EXAMPLES
JS Practice Examples JS FAQ's Answers
JAVASCRIPT REFERENCE
  • JS Properties and Methods
    • JS Array Object
    • JS Boolean Object
    • JS Date Object
    • JS Math Object
    • JS Number Object
    • JS String Object
  • JS Reserved Keywords
  • More references
Advertisements

JavaScript Window Navigator

In this tutorial you will learn about the JavaScript window navigator object.

The Navigator Object

The navigator property of a window (i.e. window.navigator) is a reference to a Navigator object; it is a read-only property which contains information about the user's browser.

Since Window is a global object and it is at the top of the scope chain, so properties of the Window object such as window.navigator can be accessed without window. prefix, for example window.navigator.language can be written as navigator.language.

The following section will show you how to get various information about user's browser.

Detect Whether the Browser is Online or Offline

You can use the navigator.onLine property to detect whether the browser (or, application) is online or offline. This property returns a Boolean value true meaning online, or false meaning offline.

Example

Try this code »
<script>
function checkConnectionStatus() {
    if(navigator.onLine) {
        alert("Application is online.");
    } else {
        alert("Application is offline.");
    }
}
</script>
 
<button type="button" onclick="checkConnectionStatus();">Check Connection Status</button>

Browser fires online and offline events when a connection is establish or lost. You can attach handler functions to these events in order to customize your application for online and offline scenarios.

Let's take a look at the following JavaScript code to see how this works:

Example

Try this code »
<script>
function goOnline() {
    // Action to be performed when your application goes online
    alert("And we're back!");
}

function goOffline() {
    // Action to be performed when your application goes offline
    alert("Hey, it looks like you're offline.");
}

// Attaching event handler for the online event
window.addEventListener("online", goOnline);

// Attaching event handler for the offline event
window.addEventListener("offline", goOffline);
</script>

<p>Toggle your internet connection on/off to see how it works.</p>

The goOffline() function in the above example will be called automatically by the browser whenever the connection goes offline, whereas the goOnline() function will be called automatically by the browser when the connection status changes to online.


Check Whether Cookies Are Enabled or Not

You can use the navigator.cookieEnabled to check whether cookies are enabled in the user's browser or not. This property returns a Boolean value true if cookies are enabled, or false if it isn't.

Example

Try this code »
<script>
function checkCookieEnabled() {
    if(navigator.cookieEnabled) {
        alert("Cookies are enabled in your browser.");
    } else {
        alert("Cookies are disabled in your browser.");
    }
}
</script>
 
<button type="button" onclick="checkCookieEnabled();">Check If Cookies are Enabled</button>

Tip: You should use the navigator.cookieEnabled property to determine whether the cookies are enabled or not before creating or using cookies in your JavaScript code.


Detecting the Browser Language

You can use the navigator.language property to detect the language of the browser UI.

This property returns a string representing the language, e.g. "en", "en-US", etc.

Example

Try this code »
<script>
function checkLanguage() {
    alert("Your browser's UI language is: " + navigator.language);
}
</script>
 
<button type="button" onclick="checkLanguage();">Check Language</button>

Getting Browser Name and Version Information

The Navigator object has five main properties that provide name and version information about the user's browser. The following list provides a brief overview of these properties:

  • appName — Returns the name of the browser. It always returns "Netscape", in any browser.
  • appVersion — Returns the version number and other information about the browser.
  • appCodeName — Returns the code name of the browser. It returns "Mozilla", for all browser.
  • userAgent — Returns the user agent string for the current browser. This property typically contains all the information in both appName and appVersion.
  • platform — Returns the platform on which browser is running (e.g. "Win32", "WebTV OS", etc.)

As you can see from the above descriptions, the value returned by these properties are misleading and unreliable, so don't use them to determine the user's browser type and version.

Example

Try this code »
<script>
function getBrowserInformation() {
	let info = "\n App Name: " + navigator.appName;
	   info += "\n App Version: " + navigator.appVersion;
	   info += "\n App Code Name: " + navigator.appCodeName;
	   info += "\n User Agent: " + navigator.userAgent;
	   info += "\n Platform: " + navigator.platform;

    alert("Here're the information related to your browser: " + info);
}
</script>
 
<button type="button" onclick="getBrowserInformation();">Get Browser Information</button>

Check Whether the Browser is Java Enabled or Not

You can use the method javaEnabled() to check whether the current browser is Java-enabled or not.

This method simply indicates whether the preference that controls Java is on or off, it does not reveal whether the browser offers Java support or Java is installed on the user's system or not.

Example

Try this code »
<script>
function checkJavaEnabled() {
    if(navigator.javaEnabled()) {
        alert("Your browser is Java enabled.");
    } else {
        alert("Your browser is not Java enabled.");
    }
}
</script>
 
<button type="button" onclick="checkJavaEnabled();">Check If Java is Enabled</button>
Previous Page Next Page
Advertisements
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties
Advertisements

Is this website helpful to you? Please give us a like, or share your feedback to help us improve. Connect with us on Facebook and Twitter for the latest updates.

About Us

Our Story Terms of Use Privacy Policy

Contact

Contact Us Report Error Guest Posts Advertise

Interactive Tools

Bootstrap Icon Search Utility HTML Formatter Title & Meta Length Calculator HTML Color Picker Bootstrap Button Generator SQL Playground Font Awesome Icon Finder HTML Editor

TutorialRepublic

BMC
Copyright © 2026 Tutorial Republic. All Rights Reserved.
Share This:
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.