Monitor network status with JavaScript
How to monitor network status with JavaScript
To check the network connection:
if (navigator.onLine) {
alert('You are online');
} else {
alert('You are offline');
}
And to detect changes in the network status (when the computer goes online or offline):
window.addEventListener('online', () => alert('You are online'));
window.addEventListener('offline', () => alert('You are offline'));