<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下載地址
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.