HTML5 includes a property on the navigator object that is supposed to tell you if the browser is online or offline, via
navigator.onLine
Sometimes, you’ll need to know if your user is viewing the page offline or online. For example, in a web mail app, saving a draft while online involves sending it to the server to be saved in a database; but while offline, you would want to save that information locally instead, and wait until the user is back online to send it to your server.
Browsers that support Offline Web Applications give you access to the navigator.onLine property, which will be true if the browser is online, and false if it’s not.
snippet
function determineConnectivity() {
if (navigator.onLine) {
// alert("You are online.");
} else {
alert("You must be offline.");
}
}