js判断浏览器是否是移动端、判断是否是微信内置浏览器

多种方法

直接改window.location.href=B页面;这句话即可

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();

更多方法:
引用:https://www.cnblogs.com/ldlx-mars/p/7666854.html


判断是否微信浏览器【动作使用了jq,不过自己可以改】

var is_weixin = (function(){
    
    return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
if(is_weixin){
    
    
    $(function(){
    
    
        return true;
    });
}else{
    
    
    $(function(){
    
    
        return false;
    });
}

更多方法:https://blog.csdn.net/ltmtianming/article/details/78323985

猜你喜欢

转载自blog.csdn.net/wwppp987/article/details/109160678