h5app下载页,判断运行环境。跳转对应的应用市场。

 

<script>
$(document).ready(function(){
function judgeBrand(sUserAgent) {
var isIphone = sUserAgent.match(/iphone/i) == "iphone";
var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
var isHonor = sUserAgent.match(/honor/i) == "honor";
var isOppo = sUserAgent.match(/oppo/i) == "oppo";
var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
var isVivo = sUserAgent.match(/vivo/i) == "vivo";
var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
var isSamsung = sUserAgent.match(/sm-/i) == "sm-";

// 如果为苹果环境
if (isIphone) {
return 'iphone';
// 如果为华为环境
} else if (isHuawei || isHonor) {
return 'huawei';
// 如果为OPPO环境
} else if (isOppo || isOppoR15) {
return 'oppo';
// 如果为vivo环境
} else if (isVivo) {
return 'vivo';
// 如果为小米环境
} else if (isXiaomi || isRedmi || isXiaomi2s) {
return 'xiaomi';
// 如果为三星环境
} else if (isSamsung) {
return 'samsung';
} else {
return 'default';
}
}

var brand = judgeBrand(navigator.userAgent.toLowerCase()); //调用机型判断
///使用navigator.userAgent.toLowerCase()判断登陆端是pc还是手机

//移动端的浏览器版本都比较高,可以监听DOMContentLoaded,而不是load,load会相对慢一点点,具体按事件使用情况而定。
// document.addEventListener("DOMContentLoaded", function () {
var USER_Agent = navigator.userAgent;
var MOBILE_IOS = /(iPhone|iPad|iPod|iOS)/i;
var MOBILE_Android = /(Android)/i;
var WX = /(micromessenger)/i;

// 默认从服务器下载
var consignorUrl="https://xxxxxxx;//服务器下载地址


if (WX.test(USER_Agent)) {
//如果在微信中打开则只显示一个提示用户的罩层
return;
} else if (MOBILE_IOS.test(USER_Agent)) {
// document.getElementById("WXShadow").style.display = "none";
window.location.href = "***://****"//苹果app跳转的协议
} else if (MOBILE_Android.test(USER_Agent)) {
// document.getElementById("WXShadow").style.display = "none";
// window.location.href = "***://****"//安卓app跳转的协议


// 苹果
if(brand=='iphone'){
// 华为
}else if(brand=='huawei'){
consignorUrl="market://details?id=xxx.xxx.xxx";//xxx.xxx.xxx表示应用包名
// OPPO
}else if(brand=='oppo'){
consignorUrl="market://details?id=xxx.xxx.xxx";//xxx.xxx.xxx表示应用包名
// vivo
}else if(brand=='vivo'){
consignorUrl="market://details?id=xxx.xxx.xxx";//xxx.xxx.xxx表示应用包名
// 小米
}else if(brand=='xiaomi'){
consignorUrl="market://details?id=xxx.xxx.xxx";//xxx.xxx.xxx表示应用包名
// 三星
}else if(brand=='samsung'){
consignorUrl="market://details?id=xxx.xxx.xxx";//xxx.xxx.xxx表示应用包名
// 默认
}else{

}
$("#consignor").click(function(){
window.location.href = consignorUrl//安卓app跳转的协议
})
}else{
$("#consignor").click(function(){
window.location.href = consignorUrl//安卓app跳转的协议
})
}
//如果没有唤起app则3秒后会跳转到下载地址,反之则不会跳转到下载地址。
// setTimeout(function () {
// window.location.href = "https://****";//下载地址
// }, 3000);
// });
})

</script>

posted @ 2021-12-14 11:06  前端海  阅读(1015)  评论(0编辑  收藏  举报