<script type="text/javascript"> // 获取当前用户扫描的设备 window.onload = function () { checkPhone(); } /* 判断用户手机为安卓还是iphone */ var checkPhone = function () { var _this = this /* 判断是否为微信环境 */ this.isWeiXin = navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1 ? true : false; if (_this.isWeiXin) { $(".mask").css("display", "block"); return } var agent = (navigator.userAgent || navigator.vendor || window.opera) if (agent != null) { var agentName = agent.toLowerCase() if (/android/i.test(agentName)) { _this.isAndroid = true } else if (/iphone/i.test(agentName)) { _this.isIOS = true } } } var apkUrl = ""; // 获取下载app地址 $(document).delegate(".downloadApp", "click", function (e) { var versionType = $(this).attr("versionType"); var ajaxobj = { type: "get", ajaxName: ajaxUrl.getAppListErWeiMa, }; var params = { "versionType": versionType, }; getdata(ajaxobj, params, function (data) { console.log(data); if (data.resultnum === "0000") { apkUrl = data.resultdata[0].apkURL; downloadApp(); } else { console.log("获取数据错误") } }); }); /* 点击下载按钮 */ var downloadApp = function () { // 微信环境 let _this = this checkPhone() let agent = (navigator.userAgent || navigator.vendor || window.opera) if (agent != null) { if (_this.isAndroid) { // alert(apkUrl); // 安卓包下载地址 window.location.href = apkUrl; } else { alert("暂不支持此设备,敬请期待~"); } } } </script>
H5判断当前手机使用的是安卓还是ios,并检测是否是微信登陆,给予app下载地址
最新推荐文章于 2024-07-03 02:27:14 发布