Say the user has loaded a webpage in their browser from the hard drive, ie a ‘file:’ in the url. (Eg they might have created a microsoft mhtml file of my webpage.)
How can I check for a live internet connection?
[Edit: Someone can load an html file from their hard drive, but the page might still need a live connection for the page to function correctly.]
>Solution :
Loading from a file: URL doesn’t tell you anything about whether the user has a network connection.
If it’s specifically the file: URL thing that worries you, look at document.location.protocol, which will be file: or https: or http:, etc.
If you want to know if there’s a network connection, you can look at navigator.onLine (see the link for caveats) or do a fetch to a known-good server.