求助,js如何检测 移动端 网络信号
发布网友
发布时间:2022-05-01 05:26
我来回答
共2个回答
热心网友
时间:2022-04-23 21:50
<script type="text/javascript">
function browserRedirect() {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
window.location.href=B页面;
}
}
browserRedirect(); </script>
热心网友
时间:2022-04-23 23:08
mui.plusReady(function() {
plus.networkinfo.CONNECTION_UNKNOW = "未知"; //0
plus.networkinfo.CONNECTION_NONE = "无网络链接"; //1
plus.networkinfo.CONNECTION_ETHERNET = "有线网络"; //2
plus.networkinfo.CONNECTION_WIFI = "无线网络"; //3
plus.networkinfo.CONNECTION_CELL2G = "蜂窝移动2G网络"; //4
plus.networkinfo.CONNECTION_CELL3G = "蜂窝移动3G网络"; //5
plus.networkinfo.CONNECTION_CELL4G = "蜂窝移动4G网络"; //6
if(plus.networkinfo.getCurrentType() == 1) { // 3为状态码,wifi状态码是3
mui.toast("连接失败,请检查您的网络后重试!", {
ration: "lang"
});
}
})
我用的mui框架,可判断当前网络状态