MUI determines network connectivity and monitor network changes JS

Source: Internet
Author: User

Source: Netchange problem; How to Judge network status

    • MUI is used to obtain the network type of the current device
1 functionPlusready () {2 3      varTypes = {};4 5Types[plus.networkinfo.connection_unknow] = "Unknown CONNECTION";6 7Types[plus.networkinfo.connection_none] = "NONE CONNECTION";8 9Types[plus.networkinfo.connection_ethernet] = "ETHERNET CONNECTION";Ten  OneTypes[plus.networkinfo.connection_wifi] = "WIFI CONNECTION"; A  -TYPES[PLUS.NETWORKINFO.CONNECTION_CELL2G] = "Cellular 2G CONNECTION"; -  theTYPES[PLUS.NETWORKINFO.CONNECTION_CELL3G] = "Cellular 3G CONNECTION"; -  -TYPES[PLUS.NETWORKINFO.CONNECTION_CELL4G] = "Cellular 4G CONNECTION"; -  +Alert ("Network:" +Types[plus.networkinfo.getcurrenttype ()]); -  + } A  at if(window.plus) { -  - Plusready (); -  -}Else{ -  inDocument.addeventlistener ("Plusready", Plusready,false); -  to}

  • mui Netchange event
1Mui.plusready (function() {2Document.addeventlistener ("Netchange", Onnetchange,false);3 functionOnnetchange () {4     //get current Network type5     varNT =Plus.networkinfo.getCurrentType ();6     Switch(NT) {7        CasePlus.networkinfo.CONNECTION_ETHERNET:8        CasePlus.networkinfo.CONNECTION_WIFI:9Mui.toast ("Current network is WiFi");Ten          Break; One        CasePlus.networkinfo.CONNECTION_CELL2G: A        CasePlus.networkinfo.CONNECTION_CELL3G: -        CasePlus.networkinfo.CONNECTION_CELL4G: -Mui.toast ("Current network non-wifi"); the          Break; -       default: -Mui.toast ("No network currently"); -          Break; + } -}

MUI determines network connectivity and monitor network changes JS

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.