单击链接打开APP,或自动跳转下载页
手机等移动终端上的页面中,访问链接(使用APP的自定义协议)自动打开相应的APP,若未安装该APP,则重定向至下载页面或下载链接。
网上找的不够完整,参考了下淘宝,立贴备忘。
<a href="javascript:;" id="opener" >打开客户端</a>
<script type="text/javascript">
var timer, ifr;
document.getElementById('openApp').onclick = function(e){
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
ifr = document.createElement('iframe');
ifr.src = 'myapp://xxxx'; //APP定义的打开协议
ifr.style.display = 'none';
document.body.appendChild(ifr);
//1秒内未打开APP,则跳转下载等。
timer = window.setTimeout(function(){
location.href = "http://下载链接/...";
}, 1000);
}
//摘自“淘宝”,打开APP后,自动移除下载跳转
window.onblur = function(){
if(timer){
clearTimeout(timer);
timer = null;
}
if(ifr){
document.body.removeChild(ifr);
}
}
</script>大部分代码摘自http://blog.woodbunny.com/tb.php?sc=2aab02&id=140
相关推荐
liuxudong00 2020-11-19
wwzaqw 2020-11-11
lihaoxiang 2020-11-05
CrossingX 2020-11-04
xuegangic 2020-10-17
86417413 2020-11-25
83206733 2020-11-19
86276537 2020-11-19
83266337 2020-11-19
86256434 2020-11-17
zhouboxiao 2020-11-16
rise 2020-11-22
sssdssxss 2020-11-20
windle 2020-11-10
孙雪峰 2020-10-30
xfcyhades 2020-11-20
cheidou 2020-11-19