Skip to content

Instantly share code, notes, and snippets.

@sjmach
Last active December 20, 2015 12:49
Show Gist options
  • Save sjmach/6134245 to your computer and use it in GitHub Desktop.
Save sjmach/6134245 to your computer and use it in GitHub Desktop.
How to display a dialog to a user when the internet is switched off in Phonegap.
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
document.addEventListener("offline", whenOffline, false);
return false;
}
function whenOffline() {
navigator.notification.alert(
'Sorry your internet connection is not working, please enable it !', // message
alertDismissed, // callback
'Settings', // title
'Done' // buttonName
);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment