js判断手机端操作系统(Andorid/IOS),并自动为链接添加相应下载地址

时间:2022-06-01 20:45:10
<script type="text/javascript">
$(document).ready(function(e) {
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终端
if(isAndroid == true){
alert("这是Android手机")
$("#go").attr("href","http://a.app.qq.com/o/simple.jsp?pkgname=com.xinchuang.chaofood ");
}
else if(isiOS == true){
alert("这是IOS手机")
$("#go").attr("href","https://appsto.re/cn/8Dur_.i");
}
});
</script>
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<a href="#" id="go" date-id="5555">下载app</a>