cocos2d-JS 幀聽斷網、連網事件

Cleve_baby發表於2018-07-05

cocos2d-JS 幀聽斷網、聯網事件 :

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() {
    alert("Online---正常工作");
});
EventUtil.addHandler(window, "offline", function() {
    alert("Offline ---離線工作");
});

相關文章