0
I took this model from the Phonegap website and yet it doesn’t issue an alert showing the status of the connection. I want to open the Inappbrowser that I am creating it show if it is connected on the internet via 3g or wifi and if it is not it emits an alert warning the user.
Example: Example taken from the Phonegap website
It does not issue the alert warning the state of the connection, how to do this?
<!DOCTYPE html>
<html>
<head>
<title>navigator.connection.type Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<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';
alert('Connection type: ' + states[networkState]);
}
</script>
</head>
<body>
<p>A dialog box will report the network state.</p>
</body>
</html>
how’s your code?
– Math
Math, is the way it is on the site really, Nest elink ai... I just copied and pasted in the application, I circled it in the emulating Eclipse on the connected smartphone on the internet and not emit any alert.
– Paulo Roberto
It would help if you put it right here in the body of your question, not always people click on the link to see or the link has much more information than necessary.
– Math
I’m new here Math, I didn’t put the code, because I don’t know how to put it... Do you help me? How do I put an HTML code here in the question?
– Paulo Roberto
Click edit, copy and paste it into your question, then you select your code and click on the icon
{}
(code sample), if you are having difficulties we repair, but try.– Math
Okay, there’s the code.
– Paulo Roberto
To check internet connection, one can use a Ping.
– Tony
In the documentation it says that before version 2.2.0, the object
connection
was innavigator.network.connection
... maybe that’s what.– Miguel Angelo
Miguel, this example has already been taken from version 3.0, the site is well organized and contains an example for each version... I’m using version 3.0 and I took the example of version 3.0, it would not have why not work, this site of Phonegap is very messed up!
– Paulo Roberto