Directly on the code
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链接
var
ifr = document.createElement(
‘iframe‘
);
ifr.src =
‘myApp://‘
;
ifr.style.display =
‘none‘
;
document.body.appendChild(ifr);
window.setTimeout(
function
(){
document.body.removeChild(ifr);
},3000)
};
</script>
2. Of course, if you are designing a two-dimensional code, you can use the following code:
<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --><a href="http://www.baidu.com"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 =‘myApp://‘; ifr.style.display =‘none‘; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000) }; document.getElementById(‘openApp‘).click(); |
Which one to use depends on your actual scene!
Android Web page Click event to jump to app