js判断Android和Ios

发布时间:2020-01-14 22:00:15发布者:Mr.Zhang阅读(402)

<!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;
}




本文转自博客园,原文地址:https://www.cnblogs.com/zhangyuxin0219/p/12192593.html

自己做的一款记账小程序,请多多支持