document.getElementById(‘openApp’).onclick = function(e){
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止js其他行为
if(/micromessenger/i.test(navigator.userAgent)){
alert(“当前是微信浏览器”)
}else if(/i(os|phone|pad)/i.test(navigator.userAgent)){
alert(“当前是ios其他浏览器”)
}else{
alert(“当前是andriod其他浏览器”)
}
var ifr = document.createElement(‘iframe’);
ifr.src = ‘com.baidu.tieba://’;//打开app的协议,有app同事提供
ifr.style.display = ‘none’;
document.body.appendChild(ifr);
window.setTimeout(function(){
document.body.removeChild(ifr);
window.location.href = “https://itunes.apple.com/cn/app/id477927812“;//打开app下载地址,有app同事提供
},2000)
};
js原生交互-js打开app
最新推荐文章于 2024-06-12 19:12:14 发布