微信网页点击按钮下载app,启动app

https://www.jianshu.com/p/3d1e48b9ec7c(参考博客地址)
先判断是否在微信或者qq环境中,让用户在浏览器中进行操作
网页无法准确判断用户是否安装了app(只能在规定时间段内若未启动则直接去下载使用延时函数实现)
下载和启动链接都是ios安卓人员提供 代码如下:

启动app
var is_weixin = (function() { //判断微信UA
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == “micromessenger”) {
return true;
} else {
return false;
}
})();
var is_qq = (function() { //判断微信UA
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/QQ/i) == “qq”) {
return true;
} else {
return false;
}
})();
var is_qqbrowser = (function() { //判断QQ浏览器
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/mqqbrowser/i) == “mqqbrowser”) {
return true;
} else {
return false;
}
})();
var tip = document.getElementById(‘weixin-tip’);
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(isiOS) { //调用ios的链接
//alert(‘ios’);
if(is_weixin || is_qq) {
//alert(‘ios’);
//tip.style.height = winHeight + ‘px’; //兼容IOS弹窗整屏
tip.style.display = ‘block’;
} else {
//alert(‘ios启动’);
window.location.href = “hrtZhanYeBao://”; /启动app的地址/
window.location.href = “https://apps.apple.com/cn/app/id1159546710”; /下载app的地址/
}

} else {
if(is_weixin || is_qq) {
tip.style.display = ‘block’;
} else {
//alert(‘安卓启动’);
window.location.href = “hrtagent://agent”; /打开app的协议启动app,有安卓同事提供/
window.location.href = “https://download.hrtpayment.com/download/hrtapp_zyb.html”; /下载app,有安卓同事提供/
}

}

var is_weixin = (function() { //判断微信UA
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == “micromessenger”) {
return true;
} else {
return false;
}
})();
var is_qq = (function() { //判断微信UA
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/QQ/i) == “qq”) {
return true;
} else {
return false;
}
})();
var is_qqbrowser = (function() { //判断QQ浏览器
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/mqqbrowser/i) == “mqqbrowser”) {
return true;
} else {
return false;
}
})();
var tip = document.getElementById(‘weixin-tip’);
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(isiOS) { //调用ios的链接
//alert(‘ios’);
if(is_weixin || is_qq) {
//alert(‘ios’);
//tip.style.height = winHeight + ‘px’; //兼容IOS弹窗整屏
tip.style.display = ‘block’;
} else {

}

} else {
if(is_weixin || is_qq) {
tip.style.display = ‘block’;
} else {

}

}

你可能感兴趣的:(微信网页点击按钮下载app,启动app)