if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { var loadDateTime = new Date(); window.location = "...";//schema鏈接或者universal link window.setTimeout(function() { //如果沒有安裝app,便會執行setTimeout跳轉下載頁 var timeOutDateTime = new Date(); if (timeOutDateTime - loadDateTime < 5000) { window.location = "..."; //ios下載地址 } else { window.close(); } }, 500); } else if (navigator.userAgent.match(/android/i)) { var state = null; try { window.location = '...'; //schema鏈接或者universal link window.setTimeout(function() { window.location = "..."; //android下載地址 }, 500); } catch (e) {} } },
因為h5頁面無法直接獲取APP是否安裝,所以只能夠間接進行判斷,就是通過跳轉的方式,如果跳轉到APP成功,則會直接調轉,如果不成功就彈出APP的下載鏈接
其中
schema鏈接需要自己在項目里面進行配置,這里附上uni-app的官網說明鏈接,https://ask.dcloud.net.cn/article/409,希望能給在摸索中的碼友些一點點幫助哦。