时间:2021-07-01 10:21:17 帮助过:10人阅读
function getNetworkType() { var ua = navigator.userAgent; var networkStr = ua.match(/NetType\/\w+/) ? ua.match(/NetType\/\w+/)[0] : 'NetType/other'; networkStr = networkStr.toLowerCase().replace('nettype/', ''); var networkType; switch (networkStr) { case 'wifi': networkType = 'wifi'; break; case '4g': networkType = '4g'; break; case '3g': networkType = '3g'; break; case '3gnet': networkType = '3g'; break; case '2g': networkType = '2g'; break; default: networkType = 'other'; } return networkType; }
以上就是js实现获取网络类型的方法的详细内容,更多请关注Gxl网其它相关文章!