使用js获取手机的网络状态
/*
* 根据connection.effectiveType判断网络类型
* connection.effectiveType有以下几种类型:
* bluetooth //蓝牙连接
* cellular //数据连接(例如,EDGE,HSPA,LTE等)。
* ethernet //以太网连接。
* none //无网络连接。
* mixed //用户代理正在使用多种连接类型。
* other //已知的连接类型,但不是枚举连接类型之一。
* unknown //用户代理已建立网络连接,但无法或不愿意确定基础连接技术。
* wifi //Wi-Fi连接。
* wimax //WiMAX连接
*/
connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
consoloe.log(connection.effectiveType)
相关文档参考:
http://wicg.github.io/netinfo/