http://zccst.iteye.com/blog/2194229
获取用户的联网状态
if (navigator && navigator.onLine === false) { alert("无法连接网络")}else{ alert("正常上网")}
监听事件
var el = document.body; if (el.addEventListener) { window.addEventListener("online", function () { alert("online");}, true); window.addEventListener("offline", function () { alert("offline");}, true); } else if (el.attachEvent) { window.attachEvent("ononline", function () { alert("online");}); window.attachEvent("onoffline", function () { alert("offline");}); } else { window.ononline = function () { alert("online");}; window.onoffline = function () { alert("offline");}; }