js ipad机型判断

由于新版iPad浏览器没有带有iPad字符串,导致iPad会判断成电脑端,

 var ua = navigator.userAgent;
                var isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
                var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1
                var isIPad = isSafari && !isIphone && 'ontouchend' in document;
                if (!/iphone|ios|ipad|android|mobile/i.test(navigator.userAgent.toLowerCase()) && !isIPad) {
                    // location.href = "qr.html?url=" + encodeURIComponent(location.href);
                    alert("pc")
                }

判断机型的 ipad的 用上面的

                const sUserAgent = navigator.userAgent.toLowerCase();
                const bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
                const bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
                const bIsMidp = sUserAgent.match(/midp/i) == "midp";
                const bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
                const bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
                const bIsAndroid = sUserAgent.match(/android/i) == "android";
                const bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
                const bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
                if (bIsAndroid) {

                    return true
                } else {

                    return false
                }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。