当前位置 : 主页 > 网络编程 > JavaScript >

js判断当前为pc端还是wap端

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt var checkBrowser;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
gistfile1.txt
var checkBrowser;
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)) {
//            pc
        checkBrowser=0;
    }else{
//            wap
        checkBrowser=1;
    }
}
// 用navigator.userAgent判断设备类型
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    alert('客户端');
} else {
    alert('PC端');
    console.log('PC端');    
}




s判断是移动端设备还是pc端设备代码,js移动端设备判断方法比较多,各路大神给出了各种设备判断方法,你看中哪个用哪个

 这个移动端判断代码比较少根据navigator.userAgent判断


 这个移动端判断代码比较少根据navigator.userAgent来判断


 这个移动端判断代码比较少根据navigator.userAgent来判断


 下面这个移动端判断代码可以针对IE内核webkit内核判断,还能判断语言


 微软office365对手机等移动端设备判断的js代码

网友评论