Notify users, that application has gone offline.

How to enable offline detection using simple browser APIs

Pulkit Aggarwal
Simple JS

--

A Web app is highly dependant on the active internet. In the absence of internet, no transaction can be done with in the application. Thus it is very important to detect and inform the user, whenever application goes offline.

window.addEventListener(‘online’, updateOnlineStatus);
window.addEventListener(‘offline’, updateOnlineStatus);
function updateOnlineStatus(event) {
var condition = navigator.onLine ? “online” : “offline”;
document.body.className = condition;
}

STEP 1. Add event listeners

A place to observe in the offline mode.

--

--