I have developed and packaged an offline Cordova-based HTML5 App for Android. It works fine, and some of the resources are accessed locally without an internet connection while other require an internet connection. A problem kicks in when the internet connection is down because it displays a Webpage, not available error together with the URL.
I have tried adding this to my HTML page, but it does not work
<img src='http://www.example.com/mobile/index.html' onerror='alert("Connection dead");' />
What problem is there with the above code?
Why don't you use cordova network plugin to test connectivity?
cordova plugin add cordova-plugin-network-information
Github - https://github.com/apache/cordova-plugin-network-information
Simple example -
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();