Something like this (not every browser supports these events, currently only IE 8.9 and FF> 3 support these events):
var el = document.body; if (el.addEventListener) { el.addEventListener("online", function () { alert("online");}, true); el.addEventListener("offline", function () { alert("offline");}, true); } else if (el.attachEvent) { el.attachEvent("ononline", function () { alert("online");}); el.attachEvent("onoffline", function () { alert("offline");}); } else { el.ononline = function () { alert("online");}; el.onoffline = function () { alert("offline");}; }
Browser support is changing, check this out: http://help.dottoro.com/ljnasgpu.php
source share