当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js判断Android和Ios

js判断Android和Ios

2020年01月15日  | 移动技术网IT编程  | 我要评论
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>android&ios</title>
</head>

<body>
<button id='btn' onclick="test()">点击</button>
</body>

</html>
<script type="text/javascript">
var u = navigator.useragent;
console.log(navigator.useragent.match())
var isandroid = u.indexof('android') > -1 || u.indexof('adr') > -1; //android终端

var isios = !!u.match(/\(i[^;]+;( u;)? cpu.+mac os x/); //ios终端
function test() {
if (isandroid == true) {
console.log("安卓手机")
} else if(isios == true) {
console.log("苹果手机")
}else{
console.log("不是手机")
}
}
</script>


&&&&&&&&&&&&&&&&&&&&&&&&

// 判断安卓
function isandroid() {
var u = navigator.useragent;
if (u.indexof("android") > -1 || u.indexof("linux") > -1) {
if (window.showfitness !== undefined) return true;
}
return false;
}
// 判断设备为 ios
function isios() {
var u = navigator.useragent;
if (u.indexof("iphone") > -1 || u.indexof("ios") > -1) {
return true;
}
return false;
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网