Detecting Internet Connection with JavaScript

html, javascript

Solution

In HTML5, you can use:

 navigator.onLine

to detect internet connectivity.

LIVE DEMO: http://jsfiddle.net/DerekL/fHQK4/

Problem

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.

Original source

Related problems