Check online status
Simpe way to check online status using JS.
The idea behind the requests is to check for online status and not just the network status.
<div id="status">Status?</div>
<script>
const checkOnlineStatus = async () => {
try {
const online = await fetch("https://your-domain/favicon.ico");
console.log(online.status, '?????');
return online.status >= 200 && online.status < 300; // either true or false
} catch (err) {
console.log('ERROR!');
return false; // definitely offline
}
};
setInterval(async () => {
const result = await checkOnlineStatus();
const statusDisplay = document.getElementById("status");
statusDisplay.textContent = result ? "Online" : "OFFline";
}, 2000); // probably too often, try 30000 for every 30 seconds
</script>