Currently, I'm making a Cached iPhone-app with some features that require internet, and other features that don't. I'd like to know how to detect an internet connection with JavaScript, to make certain pages display a 'No Internet Connection' text, and others to work as normal.
JavaScript has a function called navigator. This browser property can be used to determine if you are connected to the internet. It returns true or false depending on the status of the client's network and says whether the browser is online or offline easily.
Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top.
onLine. Returns the online status of the browser.
In HTML5, you can use:
navigator.onLine
to detect internet connectivity.
LIVE DEMO: http://jsfiddle.net/DerekL/fHQK4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With