/*
* This function be call when user connect or disconnecet with internet
*/
function updateStatus() {
// Do something in there
}
/*
* Code for user is connecting with internet
*/
if (navigator.onLine) {
// Do something in there
}
// Usage
window.addEventListener('online', updateStatus);
window.addEventListener('offline', updateStatus);