Skip to main content
12 events
when toggle format what by license comment
Apr 10 at 8:50 comment added spierala I think the online/offline events are not the best way. E.g. if you select another Wifi where you do not have access to, you will lose internet connection. Still there is no offline event. Same with flight-mode enabled: No offline event. I checked in Chrome. Checking for failing XHR requests seems to be the much more reliable option to check if there is a working internet connection (see other answers).
Dec 11, 2023 at 15:17 comment added Didier L @imike it appears to be now
Dec 10, 2023 at 10:38 vote accept Daniel Silveira
May 11, 2022 at 9:12 comment added Didier L @Normal yes, this is what I mention in the last paragraph.
May 11, 2022 at 9:01 comment added Normal In addition to this answer, corresponding to the quote from Mozilla. If you really want to make sure he's connected to the "internet" and not only the "local area network LAN", you can send a small ping request (an HTTP get request) to any webserver in the world, like Google, Twitter, or even your own website. In case the response ended with a status code of success such as 200, then this means he's connected to the internet, else, he's not.
Jun 1, 2021 at 16:58 comment added imike Should be selected answer!
Apr 16, 2021 at 14:36 comment added Didier L @Sagar I checked in Firefox and Chrome, if I unplug the cable while connected to my work VPN, they both quickly detect the deconnection. They don't wait for the VPN to reconnect to report an online status though – as I indicated in the answer, online just means you have some sort of connection, not that you have internet access. I took this opportunity to put a snippet in my answer to test it.
Apr 16, 2021 at 14:31 history edited Didier L CC BY-SA 4.0
Replaced link to demo with a Stack Snippet showing the behaviour.
Apr 16, 2021 at 14:04 comment added Sagar While vpn is connected then if we disconnect internet then window.navigator.onLine does not work
Jun 20, 2020 at 9:12 history edited CommunityBot
Commonmark migration
May 27, 2020 at 4:56 comment added TeeJaay I recently had the opportunity to work a little bit on offline behaviour. The events are great to use, BUT ios safari will create problems. When you turn of the internet on your phone the offline/online events will be delayed by up to 2 seconds and that can be problematic for visual rendering reasons, as you can't predict the future. That's just something I wanted to mention and might help someone.
Dec 17, 2018 at 17:25 history answered Didier L CC BY-SA 4.0