These events must be connected inside "onDeviceReady", they will not work before the DeviceReady event. Check Attach an Event Listener after a deviceready Event Occurs
bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); document.addEventListener('resume', this.onDeviceResume, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); document.addEventListener('online', this.onDeviceOnline, false); },
Please note that when the application starts, the online / offline event does not start, this event is triggered only when the connection status changes. Say, when an application is launched online, until it goes offline, an offline event will not be triggered, the same for an online event.
To check your current connection, you need to use the code below
onDeviceReady: function() { app.receivedEvent('deviceready'); document.addEventListener('online', this.onDeviceOnline, false); if((navigator.network.connection.type).toUpperCase() != "NONE" && (navigator.network.connection.type).toUpperCase() != "UNKNOWN") { this.onDeviceOnline(); } }
source share