window.addEventListener("online", function() {
alert("You are online now!");
});
window.addEventListener("offline", function() {
alert("Oops! You are offline now!");
});
if (navigator.onLine) {
console.log("You are online");
} else {
console.log("You are offline");
}