online
The online event is fired when the browser has gained access to the network and the value of navigator.onLine switched to true.
Note: That event shouldn't be used to determine the availability of a particular website. Network problems or firewalls might still prevent that website to be reached
offline
The offline event is fired when the browser has lost access to the network and the value of navigator.onLine switched to false.
可以通过online、offline事件来检测当前网络是否正常
//联网
document.addEventListener( "online", function () {
tr( 'online!');
Router.check_url();
}, false);
//网络断开
document.addEventListener( "offline", function () {
do_alert( '请连接网络', '没有网络连接');
}, false);
document.addEventListener( "online", function () {
tr( 'online!');
Router.check_url();
}, false);
//网络断开
document.addEventListener( "offline", function () {
do_alert( '请连接网络', '没有网络连接');
}, false);