Is there any way to "know", via javascript
, if the internet connection has been lost?
For example, to attempt a reconnection with websocket, if it detects that the internet connection has been lost and then reestablished.
Is there any way to "know", via javascript
, if the internet connection has been lost?
For example, to attempt a reconnection with websocket, if it detects that the internet connection has been lost and then reestablished.
navigator.onLine
works really; However "onLine" does not refer to an internet connection, but a connection whatsoever. If the user is connected to a VPN, but this VPN does not have internet - navigator.onLine
will return true
also;
The best solution is to make a request of GET
for ajax to any website and if this link does not fail you know that the user (most likely) is online.