Android Web page Click event to jump to app

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.