-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ee173b
commit 011e9a3
Showing
2 changed files
with
52 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
// Check if the user is online | ||
function showOfflineAlert() { | ||
alert( | ||
"This website requires an internet connection. Please check your internet connection and try again." | ||
); | ||
} | ||
|
||
function updateOfflineUI() { | ||
document.body.innerHTML = | ||
"<div class='container'><h1>Internet connection required</h1><p>Please check your connection and reload the page.</p><button class='reload' onClick='window.location.reload();'>Reload</button></div>"; | ||
} | ||
|
||
function checkOnlineStatus() { | ||
if (!navigator.onLine) { | ||
alert( | ||
"This website requires an internet connection. Please check your internet connection and try again." | ||
); | ||
document.body.innerHTML = | ||
"<h1>Internet connection required</h1><p>Please check your connection and reload the page.</p>"; | ||
} | ||
const IsOnline = !navigator.onLine; | ||
if (IsOnline) { | ||
document.body.classList.add("online"); | ||
showOfflineAlert(); | ||
updateOfflineUI(); | ||
} else { | ||
document.body.classList.remove("offline"); | ||
} | ||
|
||
// Check online status when the page loads | ||
window.addEventListener("load", checkOnlineStatus); | ||
|
||
// Also check when the online/offline status changes | ||
window.addEventListener("online", checkOnlineStatus); | ||
window.addEventListener("offline", checkOnlineStatus); | ||
} | ||
|
||
// Check online status when the page loads | ||
window.addEventListener("load", checkOnlineStatus); | ||
|
||
// Also check when the online/offline status changes | ||
window.addEventListener("online", checkOnlineStatus); | ||
window.addEventListener("offline", checkOnlineStatus); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters