標籤: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