h5頁面喚醒app,以淘寶為例子
<a onclick="openApp()">點選喚醒app</a>
js
<script>
var download_schema = 'taobao://'; //app的協定有安卓同僚提供,這裡是用的淘寶
var universal_link = 'ios下載下傳位址';//ios下載下傳位址
var getVersionUrl = 'Android下載下傳位址';//Android移動端下載下傳位址
var u = navigator.userAgent.toLocaleLowerCase();
//console.log(u);
var isWeixin = u.match(/MicroMessenger/i) == 'micromessenger'; //判斷是不是微信浏覽器
var isAndroid = u.indexOf('android') > -1 || u.indexOf('linux') > -1; //android終端或者uc浏覽器
var isiOS = !! u.match(/(iphone|ipod|ipad|mac)/i);
function openApp() {
//alert('1');
//alert(isAndroid);
//alert(isiOS);
if (isAndroid) {
android1();
}
if (isiOS) {
ios();
}
//alert("調用下載下傳失敗"); //此處彈窗時,是沒有version參數,如果在app中打開,是會有這個參數的
}
function android1() {
//如果是微信,直接下載下傳
if (isWeixin) {
window.location.href = "Android下載下傳位址 "; /***Android移動端下載下傳位址***/
} else {
window.location.href = download_schema; /***打開app的協定,有安卓同僚提供***/
window.setTimeout(function () {
//window.location.href = "Android下載下傳位址";/***Android移動端下載下傳位址***/
window.location.href = getVersionUrl; /***Android移動端下載下傳位址***/
}, 100);
}
}
function ios() {
window.location.href = universal_link + "?schema=" + encodeURIComponent(download_schema);
}
</script>