几年前,我已经尝试过在这里发布此javascript:
<script>
if (/iP(hone|od)|android.+mobile|BlackBerry|IEMobile/i.test(navigator.userAgent)) {
window.location.replace("page2.html");
} else if (/(tablet|ipad|playbook|silk)|(android(?!.*mobile))/i.test(navigator.userAgent)) {
window.location.replace("page3.html");
}
</script>
虽然移动重定向在iphone上有效,但平板电脑/ ipad重定向在iPad(第6代或第8代)上不起作用。任何建议表示感谢。(请理解,我在任何回复中都不是编码员。)
遍历此线程之后:检测移动设备的最佳方法是什么?
使用用户代理进行重定向显然被认为是不可靠的。
引用本文:检测移动浏览器
使用屏幕分辨率之类的方法可以考虑使用此方法:
( window.innerWidth <= 800 ) && ( window.innerHeight <= 600 )
考虑以下解决方法。从注释中可以看出,来自ipadOS和MacOS的用户代理是相同的。但是navigator.maxTouchPoints
可以成为一个区别因素:
if (/mac/i.test(navigator.userAgent) && navigator.maxTouchPoints>0 ){
// do something on ipad
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句