您的位置:首页 > 移动开发 > IOS开发

H5判断移动设备为Android 或 IOS+判断移动设备是否为全面屏

2019-10-25 11:34 4996 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_45077505/article/details/102739957

下面这段代码即可判断当前移动设备是Android或者是IOS

(function () {
var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
alert('是否是Android:' + isAndroid);
alert('是否是iOS:' + isiOS);
if (isAndroid) {
$("#choose").attr('capture', 'camera');
}
})();

判断当前设备是不是全面屏,结合上面代码一起使用

/**判断屏幕大小 */
function judgeBigScreen() { //,这里根据返回值 true 或false ,返回true的话 则为全面屏
let result = false;
const rate = window.screen.height / window.screen.width;
let limit = window.screen.height == window.screen.availHeight ? 1.8 : 1.65; // 临界判断值

// window.screen.height为屏幕高度
//  window.screen.availHeight 为浏览器 可用高度

if (rate > limit) {
result = true;
}
console.log(result)
return result;
};
(function () {
var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
alert('是否是Android:' + isAndroid);
alert('是否是iOS:' + isiOS);
if (isAndroid) {
$("#choose").attr('capture', 'camera');
}
judgeBigScreen(); //判断当前设备是否为IOS全面屏
})();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: