- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I would like to know if there is a way to warn the user that their device should be connected to the internet before loading a sub page please.
Thank you.
Ben
- Tags:
- HTML5
- Intel® XDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ben,
You can use Network Information plugin to do this.
Using this, you can check any time calling a function like this:
function checkConnection() { var estadoInternet = navigator.connection.type; if (estadoInternet == "none" || estadoInternet == "unknown") { navigator.notification.beep(2); myApp.showPreloader("Para executar esta função é preciso ter conexão com a internet."); setTimeout(function () { myApp.hidePreloader(); }, 2000); return false; } else { return true; } }
Hamilton
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ben,
You can use Network Information plugin to do this.
Using this, you can check any time calling a function like this:
function checkConnection() { var estadoInternet = navigator.connection.type; if (estadoInternet == "none" || estadoInternet == "unknown") { navigator.notification.beep(2); myApp.showPreloader("Para executar esta função é preciso ter conexão com a internet."); setTimeout(function () { myApp.hidePreloader(); }, 2000); return false; } else { return true; } }
Hamilton
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Hamilton!,
Let me try now and see how it works..
Ben
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I downloaded the plugin and tried to add your code at the bottom on my index.html and stopped both my Wifi and 3G, no warnings are showing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok I am going to try with this new code, awaiting for a build to generate...
But it seems that after the 2.30 version the API code has changed to this:
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok here is the right integration steps for it to work and it works very well!
https://cordova.apache.org/docs/en/2.8.0/cordova/connection/connection.type.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ben,
I adapted the code to know only if there is connection. That´s why I check only none or unkown.
To work, I put my code inside this:
if (checkConnection()) { // do something }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks:-)
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page