使用js获取手机的网络状态

connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
根据connection.type判断网络类型,connection.type有以下几种类型:
bluetooth      //蓝牙连接  
cellular       //数据连接(例如,EDGE,HSPA,LTE等)。
ethernet       //以太网连接。
none           //无网络连接。
mixed          //用户代理正在使用多种连接类型。
other          //已知的连接类型,但不是枚举连接类型之一。
unknown      //用户代理已建立网络连接,但无法或不愿意确定基础连接技术。
wifi           //Wi-Fi连接。
wimax          //WiMAX连接
详情参考:
https://developer.mozilla.org/zh-CN/docs/Web/API/Network_Information_API
https://developer.mozilla.org/zh-CN/docs/Web/API/Navigator/connection
http://wicg.github.io/netinfo/
posted @ 2019-07-12 14:16  N土豆鸡块  阅读(1645)  评论(0)    收藏  举报