网上找的不够完整,参考了下淘宝,立贴备忘。
<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/tb.php?sc=2aab02&id=140
发布者:admin,转转请注明出处:http://www.yc00.com/web/1754590947a5179066.html
评论列表(0条)