兼容浏览器写法
var EventUtil = {
addHandler: function (element, type, handler) {
if(element.addEventListener) {
element.addEventListener(type, handler, false);
}else if (element.attachEvent) {
element.attachEvent("on" + type, handler);
}else {
element["on" + type] = handler;
}
}
};
EventUtil.addHandler(window, "online", function () {
document.write("连上网了!");
});
EventUtil.addHandler(window, "offline", function () {
document.write("网络不给力,请检查网络设置!");
});