js判断是安卓还是Ios

<!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>Document</title>
</head>

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

</html>
<script type="text/javascript">
var u = navigator.userAgent;

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) {
location.href = "http://uri6.com/tkio/3aEfmya"
console.log("安卓手机")
} else {
location.href = "http://uri6.com/tkio/MBFbAva"
console.log("苹果手机")
}
}
</script>
posted @ 2019-06-19 16:24  小小小小小前端  阅读(4682)  评论(0编辑  收藏  举报