Detect Offline / Online Network Status with Javascript

javascript
Published on December 11, 2018

The current status of the network, whether online or offline, can be found through the navigator.onLine property. This gives true if network is online or false when network is offline.

if(navigator.onLine === true)
	alert('You are online);
else
	alert('You are offline);

Demo

You are online
Go offline / online to see how the above status changes

Detecting Network Status Change with Events

You can register to online and offline events to check when user switches to online or offline mode.

window.addEventListener('online', function() {
	alert('Current status : online');
});

window.addEventListener('offline', function() {
	alert('Current status : offline');
});
In this Tutorial
    Comments
    Loading Comments