I’m having an issue with the navigator.onLine property.
I’m running a simple website from a local kiosk running on a WAMP.
On my laptop when I test this it works. I turn off WiFi and the alert box shows up. Disconnecting the internet on the kiosk running the WAMP software does not produce the false status. Any ideas why?
var online = navigator.onLine;
if (online == false) {
alert("Sorry, we currently do not have Internet access.");
location.reload();
}
MDN about navigator.onLine:
As described above, this property is not trustable, so, in my opinion, the best workaround is an ajax call to a server-side page. If the browser is offline, then the connection will fail and, thus, the
onerrorevent will be called. Otherwise, theonloadevent is called: