js判断Android和Ios
程序员文章站
2022-05-18 19:07:39
<!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;
}
上一篇: python 设置默认字典