detector
detector copied to clipboard
如何识别设备类型,Phone, Tablet(Pad) 和 Desktop ?
- 按照 UA 识别『不准确』
- 按照分辨率区分『不准确』
- 按照物理尺寸『无法获得 DPI,可以结合 CSS 但不准确』
- 按照有无 3G通信模块『无法获得』
参考
- Android Phone和Pad UA区别
- How do detect Android Tablets in general. Useragent?
- http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html
- Android 区分PAD和PHONE
- How can I detect Android phones and Android tablets differently using the user agent header?
可以增加苹果系列的区分,3、4、5、6可以通过屏幕高度window.screen.height辅助window.devicePixelRatio来判断。比如:
var iosVersioin;
if (detector.device.name == "iphone") {
var height = screen.height;
if (height == 480) {
iosVersioin = "4、4s"
} else {
if (height == 568) {
iosVersioin = "5、5s、5c"
} else {
if (height == 667) {
if(window.devicePixelRatio == 3){
iosVersioin = '6 plus';
}else{
iosVersioin = "6"
}
} else {
if (height == 736) {
iosVersioin = "6 plus"
} else {
iosVersioin = "unkown"
}
}
}
}
}
希望增加iPhone 4,5,6的检测
什么用途?
记录,用户反馈问题时可以知道是哪个型号的问题。日常error也可以快速找测试机来检查。
一般跟硬件关系不大吧,主要看操作系统、浏览器及渲染引擎的软件。
不是大家都需要这个,那我们就自己实现一下就好了。
嗯。还没想清楚,detector 暂时还没有加入这个功能的计划。