android web頁面點擊事件跳轉至APP

來源:互聯網
上載者:User

標籤:android   網頁跳轉app   uri sheme   

直接上代碼

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.當然,如果你是設計成一張二維碼,可以用下面這段代碼:

<!-- 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();

要使用哪一種,就取決與你的實際情境了!


android web頁面點擊事件跳轉至APP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.