I am using this cordova-plugin-network-information plugin with below code.
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
checkConnection();
}
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';
if(networkState != Connection.NONE){
window.location.href = "index2.html";
} else{
document.getElementById('custom-message').style.display = "block";
}
}
</script>
This plugin working fine but it redirects to 2nd page (index2).
I want to in a such way that first it checks the connection & then load the same page index page (no need to create index2 page) And if fails (No Internet) then throw the custom error message.
Thanks