---ps---最近新發現一個開源的H5喚醒app的庫:
建議使用第三方開源庫https://github.com/suanmei/callapp-lib實現;
或者極光魔鏈(后期可能會收費)
https://www.cnblogs.com/SimonHu1993/p/10578775.html
<script type="text/javascript"> var theUrl = ''; var Terminal={}; var startTime = new Date().getTime(); // 獲取終端的相關信息 window.onload=function(){ Terminal = { // 辨別移動終端類型 platform : function(){ return { // android終端或者uc瀏覽器 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, // 是否為iPhone或者QQHD瀏覽器 iPhone: u.indexOf('iPhone') > -1 , // 是否iPad iPad: u.indexOf('iPad') > -1, //是否為微信 mic:u.indexOf('MicroMessenger') > -1, }; }(), language:(navigator.browserLanguage || navigator.language).toLowerCase() } // 根據不同的終端,跳轉到不同的地址 if(Terminal.platform.mic) { document.getElementById("dow").onclick=function(){ document.getElementById("dow").style.display="none"; } var _a=document.getElementById("dow_a").getElementsByTagName("a"); for(var i=0; i<_a.length; i++){ _a[i].onclick=function(){ document.getElementById("dow").style.display="block"; } } return false; }else{document.getElementById("dow").style.display="none";} if(Terminal.platform.android){ theUrl = 'https://api.zihexin.net/download/zihexin_1.0.apk'; }else if(Terminal.platform.iPhone){ theUrl = 'https://itunes.apple.com/cn/app/zi-he-xin/id581817870?mt=8'; }else if(Terminal.platform.iPad) { theUrl = 'https://itunes.apple.com/cn/app/zi-he-xin/id581817870?mt=8'; }else{ theUrl = 'https://api.zihexin.net/download/zihexin_1.0.apk'; } //location.href = theUrl; } var clipboard = new Clipboard('#bodyBar'); clipboard.on('success', function(e) { e.clearSelection(); }); clipboard.on('error', function(e) { }); function copydata(){ var url = window.location; $('#bodyBar').attr('data-clipboard-text',url); if(Terminal.platform.mic){ alert('請點擊本頁面右上角選擇使用瀏覽器打開!'); return false; } openApp('zihexin://openapp',theUrl,'',openUrl) } //是否打開下載頁面 function openUrl(opened){ if(opened == 0){ window.location.href = theUrl; } } function openApp(openUrl, appUrl, action, callback) { //檢查app是否打開 function checkOpen(cb){ var _clickTime = +(new Date()); function check(elsTime) { if ( elsTime > 3000 || document.hidden || document.webkitHidden) { cb(1); } else { cb(0); } } //啟動間隔20ms運行的定時器,並檢測累計消耗時間是否超過3000ms,超過則結束 var _count = 0, intHandle; intHandle = setInterval(function(){ _count++; var elsTime = +(new Date()) - _clickTime; if (_count>=100 || elsTime > 3000 ) { clearInterval(intHandle); check(elsTime); } }, 20); } //在iframe 中打開APP var ifr = document.createElement('iframe'); ifr.src = openUrl; ifr.style.display = 'none'; if (callback) { checkOpen(function(opened){ callback && callback(opened); }); } document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); }, 2000); } </script>
參考https://www.cnblogs.com/shadajin/p/5724117.html
本方案對部分安卓瀏覽器可能出現不兼容,出現打開‘XX’app的提示,導致操作時間過長,判斷失誤,網上很多根據時間差跳轉的都會有此問題,暫未找到兼容性較好的方式,
針對ios9以上的系統,universal link方式可自行了解。