直接上代码
1.而对于点击链接后,能否直接打开,可以通过下面的代码来实现。前提条件:你得知道你的APP对应的打开协议,在<intent-filter>中设置scheme。如微信,协议为:weixin:// ,and so on。。。
<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --><a href="http://www.baidu.com" id="openApp">打开APP</a><script type="text/javascript"> document.getElementById(‘openApp‘).onclick =function(e){ // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 varifr = document.createElement(‘iframe‘); ifr.src =‘myApp://‘; ifr.style.display =‘none‘; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000) };</script>
2.当然,如果你是设计成一张二维码,可以用下面这段代码:
<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --><a href="http:// id="openApp"style="display:
none">贴吧客户端</a><script type="text/javascript"> document.getElementById(‘openApp‘).onclick =function(e){ // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 varifr = document.createElement(‘iframe‘); ifr.src =‘; ifr.style.display =‘none‘; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000) }; document.getElementById(‘openApp‘).click(); |
要使用哪一种,就取决与你的实际场景了!
原文地址:http://blog.csdn.net/gyz413977349/article/details/42171503