One, network connection status list
Phonegap network connection through the Navigator.network.connection.type to get, generally have a few states
1. Connection.unknown Unknown connection
2. Connection.ethernet Ethernet
3. Connection.wifi WIFI
4. CONNECTION.CELL_2G 2G Network
5. CONNECTION.CELL_3G 3G Network
6. CONNECTION.CELL_4G 4G Network
7. Connection.none No network connection
Second, the Code implementation
<!DOCTYPE HTML> <HTML><Head><MetaCharSet= "Utf-8"><title>Phonegap_device_network_notification01</title><Linkhref=".. /jquery.mobile-1.3.2.css "rel= "stylesheet"type= "Text/css"/><Scriptsrc=".. /jquery.js "type= "Text/javascript"></Script><Scriptsrc=".. /jquery.mobile-1.3.2.js "type= "Text/javascript"></Script><Scriptsrc=".. /cordova.js "type= "Text/javascript"></Script><Scripttype= "Text/javascript"CharSet= "Utf-8">Document.addeventlistener ("Deviceready", Ondeviceready,false); functionOndeviceready () {//Monitor changes in the network //Window.addeventlistener ("online", Ononline, false); //Window.addeventlistener ("Offline", Onoffline, false); //console.log (' network type ' +navigator.network.connection.type);Alert ('Network Type'+navigator.network.connection.type);//so you can detect what kind of network connection it is. //Check your network connectionchecknetworkconnection (); } functionchecknetworkconnection () {varstates= {}; //encapsulation into an arrayStates[connection.unknown]= 'Unknown Connection'; States[connection.ethernet]= 'Ethernet'; States[connection.wifi]= 'WiFi'; STATES[CONNECTION.CELL_2G]= '2G Network'; STATES[CONNECTION.CELL_3G]= '3G Network'; STATES[CONNECTION.CELL_4G]= '4G Network'; States[connection.none]= 'No network connection'; Alert ('Network Connection type:' +States[navigator.network.connection.type]); } functionOnonline () {alert ('you are now online'); } functionOnoffline () {alert ('you are offline now'); }</Script></Head> <Body><DivData-role= "page"> <DivData-role= "header"> <H1>PhoneGap100 Combat</H1> </Div> <DivData-role= "Content"> <inputtype= "button"value= "Check Network"OnClick= "checknetworkconnection ()" /> </Div> <DivData-role= "Footer"> <h4> </h4> </Div></Div></Body></HTML>
PhoneGap Detection Equipment Network connection situation