PhoneGap Detection Equipment Network connection situation

Source: Internet
Author: User

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>&nbsp;</h4>        </Div></Div></Body></HTML>

PhoneGap Detection Equipment Network connection situation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.