两种方式
方式一:简单的进行打开app,延时操作若未打开直接跳gp
function isInstalled(){
var urlFrag = ‘somepars‘;
var the_href = ‘market://****‘;//获得下载链接
window.location.href = "appname://start" + urlFrag;//打开某手机上的某个app应用
setTimeout(function(){
window.location.href = the_href;//如果超时就跳转到app下载页
},800);
}
方式二 :添加 iframe(与上无太多区别 和 性能区别)
function isInstalled() {
var timeout, t = 1000,
hasApp = true,
urlFrag = ‘somepars‘;
url = "appname://start" + urlFrag ;
var openScript = setTimeout(function() {
if (!hasApp) {
var durl = ‘market://******‘;
window.location.href = durl;
}
document.body.removeChild(ifr);
}, 2000)
var t1 = Date.now();
var ifr = document.createElement("iframe");
ifr.setAttribute(‘src‘, url);
ifr.setAttribute(‘style‘, ‘display:none‘);
document.body.appendChild(ifr);
timeout = setTimeout(function() {
var t2 = Date.now();
if (!t1 || t2 - t1 < t + 100) {
hasApp = false;
}
}, t);
}
注意:
1 有的浏览器会有安全验证的问题,可能会连续两次提示打开窗口,这样就需要提供白名单给到相应的浏览器开发者
2 该方法成功率不是100%,有的手机会完全不支持;
3 具体的market 和 打开app的协议 有产品和客户端提供;
原文:https://www.cnblogs.com/xhliang/p/10289666.html