h5分享頁面打開APP


項目中 直播app分享出來的直播h5頁面 點擊進入按鈕:已下載app 就進入app,未下載跳轉到下載頁面

 

判斷是安卓還是ios

var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android終端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端
if(isiOS){
document.getElementById('download-app').value = 'http://baidu.com';
}else{
document.getElementById('download-app').value = 'http://jd.com/8JZ5OO';
}

頁面代碼

<a id="call-app" href="javascript:;" style="display: inline-block;float: right;">
<input id="download-app" type="hidden" name="storeurl" value="http://jd.com/8JZ5OO">
<div class="intoR">
<span>立即進入</span>
</div>
</a>

已下載打開APP 未下載跳轉到input的value也就是下載頁面

scheme_IOS和scheme_Adr這兩個參數是app端給的呼起app url。

var ua = navigator.userAgent.toLowerCase();
var t;
var config = {
/*scheme:必須*/
scheme_IOS: 'lbbox1214151904://com.lababox',
scheme_Adr: 'schemedemo://aa.com/test/scheme?name=google&page=1',
download_url: document.getElementById('download-app').value,
timeout: 600
};

function openclient() {
var startTime = Date.now();

var ifr = document.createElement('iframe');

ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;
ifr.style.display = 'none';
document.body.appendChild(ifr);

var t = setTimeout(function() {
var endTime = Date.now();

if (!startTime || endTime - startTime < config.timeout + 200) {
window.location = config.download_url;
} else {

}
}, config.timeout);

window.onblur = function() {
clearTimeout(t);
}
}
window.addEventListener("DOMContentLoaded", function(){
document.getElementById("call-app").addEventListener('click',
openclient, false);
}, false);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM