移动端检测
插件通用下载: https://www.bootcdn.cn/
根据一个库 device.js
常用检测类型
- device.ipad() 返回一个布尔值(true,false),表示用户的设备是否是 ipad
| 方法 | 对应设备 |
|:---|:---|
| device.portrait() | 检测设备是否是竖直的; |
| device.landscape() | 检测设备是否是水平的; |
| device.mobile() | 检测设备是否是手机; |
| device.ipad() | 检测设备是否是ipad; |
| device.iphone() | 检测设备是不是苹果手机; |
| device.android() | 检测设备是不是安卓手机; |
| device.tablet() | 检测设备是不是大屏幕手机(7寸以上) |
使用方法
- 先引入
device.js
库 - 判断类型
if(device.mobile()){ // document.write("手机")
if (device.portrait()){ // 竖直显示
location.href = "shuz.html";
} else if(device.landscape()){ // 水平显示
location.href = "shuipin.html";
}
} else if(device.tablet()){ //大屏手机
location.href = "dap.html";
}else if(device.desktop()) { // pc
location.href = "pc.html";
}