在 Chrome 中使用 Ripple 我希望在我将网络从连接状态(WiFi、4g 等)切换到无状态时调用我的在线和离线事件。但这不会发生。如果我离线启动模拟器,最多会调用离线。
部署到手机(Android)如果我进入飞行模式然后回到在线,这些事件似乎会被调用。
这是我的代码:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onOffline: function () {
var parentElement = document.getElementById("devicestatus");
var offlineElement = parentElement.querySelector('.offline');
var onlineElement = parentElement.querySelector('.online');
onlineElement.setAttribute('style', 'display:none;');
offlineElement.setAttribute('style', 'display:block;');
},
onOnline: function () {
var parentElement = document.getElementById("devicestatus");
var offlineElement = parentElement.querySelector('.offline');
var onlineElement = parentElement.querySelector('.online');
offlineElement.setAttribute('style', 'display:none;');
onlineElement.setAttribute('style', 'display:block;');
},
onDeviceReady: function() {
var parentElement = document.getElementById("devicestatus");
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
document.addEventListener('offline', app.onOffline, false);
document.addEventListener('online', app.onOnline, false);
}
};
这是 Ripple 中的错误还是我做错了什么?