window.addEventListener('online' , function(){alert('online');},false);
window.addEventListener('offline' , function(){alert('offline');},false);
online,offline事件官方说明:
http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html
window.navigator.onLine
Returns false if the user agent is definitely offline (disconnected from the network). Returns true if the user agent might be online.
The eventsonlineandofflineare fired when the value of this attribute changes.
Thenavigator.onLineattribute must return false if the user agent will not contact the network when the user follows links or when a script requests a remote page (or knows that such an attempt would fail), and must return true otherwise.