gpt4 book ai didi

javascript - 如何检测Android平板浏览器?

转载 作者:行者123 更新时间:2023-11-30 06:29:35 24 4
gpt4 key购买 nike

我使用以下代码来检测手机/平板电脑浏览器。

function isMobile() {
var index = navigator.appVersion.indexOf("Mobile");
return (index > -1);
}

它在桌面浏览器和 iOS 设备(iPhone/iPad)上运行良好,但无法检测到某些 Android 平板电脑或移动设备。

我也使用了以下代码 fragment ,但也没有用。

var Environment = {
//mobile or desktop compatible event name, to be used with '.on' function
TOUCH_DOWN_EVENT_NAME: 'mousedown touchstart',
TOUCH_UP_EVENT_NAME: 'mouseup touchend',
TOUCH_MOVE_EVENT_NAME: 'mousemove touchmove',
TOUCH_DOUBLE_TAB_EVENT_NAME: 'dblclick dbltap',

isAndroid: function() {
return navigator.userAgent.match(/Android/i);
},
isBlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
isIOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
isOpera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
isWindows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
isMobile: function() {
return (Environment.isAndroid() || Environment.isBlackBerry() || Environment.isIOS() || Environment.isOpera() || Environment.isWindows());
}
};

任何人都可以告诉我是否有任何错误或我需要使用任何其他方法。

最佳答案

访问here

function isTouchDevice() {
var el = document.createElement('div');
el.setAttribute('ongesturestart', 'return;');
return typeof el.ongesturestart === "function";
}

关于javascript - 如何检测Android平板浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18691822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com