优化对移动设备的识别

This commit is contained in:
晚风拂柳颜 2023-06-09 16:17:28 +08:00
parent 90fc0ef7e8
commit 1f36630a34
2 changed files with 4 additions and 3 deletions

View File

@ -1 +1 @@
3.9.43beta5
3.9.43beta6

View File

@ -21,10 +21,11 @@
function isPhone() {
//获取浏览器navigator对象的userAgent属性浏览器用于HTTP请求的用户代理头的值
var info = navigator.userAgent;
console.log('navigator.userAgent:',info);
var isMobile = /iPhone|iPad|iPod|Android|mobile/i.test(info) || window.screen.width < 768 || window.screen.height < 768;
console.log('navigator.userAgent:',info,'isMobile:',isMobile);
//通过正则表达式的test方法判断是否包含“Mobile”字符串
//如果包含“Mobile”是手机设备则返回true
return /mobile/i.test(info);
return isMobile;
}
const IS_MOBILE = isPhone();
console.log('IS_MOBILE:',IS_MOBILE);