h5喚醒APP

h5喚醒app,以淘寶爲例子linux

HTMLandroid

<a οnclick="openApp()">點擊喚醒app</a>

JSios

<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>

做者:小小書童
網站:http://apppay.xyz瀏覽器

相關文章
相關標籤/搜索