Reputation: 513
I'm developing a jquery mobile app using phonegap build, I search on the web and I got a script on an alert which tells you are online. I've been working around the script with the intention of the alert only popping up when there's no internet but can't see to find my
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
document.addEventListener("offline", onOffline, false);
return false;
}
function onOffline() {
networkState = navigator.network.connection.type;
if (networkState == Connection.NONE)
{
alert('No internet connection ');
};
return false;
}
</script>
I've place the function in the body so it pops up
<body onLoad="onOffline()">
Upvotes: 0
Views: 68
Reputation: 2701
document.addEventListener("deviceready", onLoad, false);
var Status = "";
OR
<body onLoad="onLoad()">
function onLoad() {
document.addEventListener("offline", offLine, false);
document.addEventListener("online", onLine, false);
}
function offLine() {
alert("offLine");
if(Status != 'disconnected') {
Status = 'disconnected';
// Your code
}
}
function onLine() {
alert("onLine");
if(Status != 'connected' && Status != '') {
Status = 'connected';
}
}
Upvotes: 1