HUNG
HUNG

Reputation: 535

[PhoneGap][Check Connection] Not work from the sample in http://docs.phonegap.com

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script type="text/javascript" charset="utf-8">


function load()
{
    checkConnection();
}

function checkConnection() 
{
    alert('0000');
    var networkState = navigator.network.connection.type;

    alert('111');

    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.NONE]     = 'No network connection';
    alert('2222');
    alert('Connection type: ' + states[networkState]);

    //if (networkState != Connection.NONE){
    // redirecting to index page

}

</script>

</head>
<body onload="load()">
</body>
</html>

Hi all, I know there are many samples that used to check internet connection, I hope this will be not treated as repeated post.

I wondering why cannot process to alert 111

Is there any problems with "var networkState = navigator.network.connection.type;"

But, mostly I reference the coding from http://docs.phonegap.com

Could anyone tell me where is going wrong?

Thanks

Upvotes: 0

Views: 334

Answers (1)

Nishanth Nair
Nishanth Nair

Reputation: 2965

Seems like you are using old code on a new version of PhoneGap. PhoneGap changed connection API to use navigator.connection.type from version 2.2.0 onwards.

Upvotes: 1

Related Questions