i'm trying to detect whether the browser is connected to the internet or not using javascript. my implementation works for me on both Edge and chrome but does not works when i try to test in on another pc.
i tried clearing cache, cookie and even reinstall my browsers thinking it could be cache related but still it works on my machine but not when i try it on any other. the issue is strictly related to chrome as edge seems to work fine on any other pc.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=no">
<script type="text/javascript">
// Checking connectivity - Displays message and play sounds if lose
window.addEventListener('offline', () => {
console.log("offline");
});
window.addEventListener('online', () => {
console.log("online");
});
</script>
<title>Insert title here</title>
</head>
<body>
</body>
</html>
i wrote the above test html, which again works on chrome on my machine but does not for others. the expected result should be print offline in console when you disconnect the pc from internet and online when reconnected without the need to refresh the page.