Detect Offline / Online Network Status with Javascript

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);
	alert('You are offline);


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');

Leave a Reply

Your email address will not be published. Required fields are marked *