H5唤醒app,不完全兼容
生活随笔
收集整理的這篇文章主要介紹了
H5唤醒app,不完全兼容
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
---ps---最近新發(fā)現(xiàn)一個開源的H5喚醒app的庫:
建議使用第三方開源庫https://github.com/suanmei/callapp-lib實現(xiàn);
或者極光魔鏈(后期可能會收費)
https://www.cnblogs.com/SimonHu1993/p/10578775.html
<script type="text/javascript"> var theUrl = '';var Terminal={};var startTime = new Date().getTime();// 獲取終端的相關(guān)信息 window.οnlοad=function(){Terminal = {// 辨別移動終端類型platform : function(){return {// android終端或者uc瀏覽器android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,// 是否為iPhone或者QQHD瀏覽器iPhone: u.indexOf('iPhone') > -1 ,// 是否iPadiPad: u.indexOf('iPad') > -1,//是否為微信mic:u.indexOf('MicroMessenger') > -1,};}(),language:(navigator.browserLanguage || navigator.language).toLowerCase()}// 根據(jù)不同的終端,跳轉(zhuǎn)到不同的地址if(Terminal.platform.mic) {document.getElementById("dow").οnclick=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,超過則結(jié)束var _count = 0, intHandle;intHandle = setInterval(function(){_count++; var elsTime = +(new Date()) - _clickTime;if (_count>=100 || elsTime > 3000 ) {clearInterval(intHandle);check(elsTime);}}, 20);}//在iframe 中打開APPvar 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://github.com/suanmei/callapp-lib實現(xiàn);
或者極光魔鏈(后期可能會收費)
https://www.cnblogs.com/SimonHu1993/p/10578775.html
<script type="text/javascript"> var theUrl = '';var Terminal={};var startTime = new Date().getTime();// 獲取終端的相關(guān)信息 window.οnlοad=function(){Terminal = {// 辨別移動終端類型platform : function(){return {// android終端或者uc瀏覽器android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,// 是否為iPhone或者QQHD瀏覽器iPhone: u.indexOf('iPhone') > -1 ,// 是否iPadiPad: u.indexOf('iPad') > -1,//是否為微信mic:u.indexOf('MicroMessenger') > -1,};}(),language:(navigator.browserLanguage || navigator.language).toLowerCase()}// 根據(jù)不同的終端,跳轉(zhuǎn)到不同的地址if(Terminal.platform.mic) {document.getElementById("dow").οnclick=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,超過則結(jié)束var _count = 0, intHandle;intHandle = setInterval(function(){_count++; var elsTime = +(new Date()) - _clickTime;if (_count>=100 || elsTime > 3000 ) {clearInterval(intHandle);check(elsTime);}}, 20);}//在iframe 中打開APPvar 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
本方案對部分安卓瀏覽器可能出現(xiàn)不兼容,出現(xiàn)打開‘XX’app的提示,導致操作時間過長,判斷失誤,網(wǎng)上很多根據(jù)時間差跳轉(zhuǎn)的都會有此問題,暫未找到兼容性較好的方式,
針對ios9以上的系統(tǒng),universal link方式可自行了解。
轉(zhuǎn)載于:https://www.cnblogs.com/SimonHu1993/p/10183908.html
總結(jié)
以上是生活随笔為你收集整理的H5唤醒app,不完全兼容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 增强学习--蒙特卡洛方法
- 下一篇: day-17 包与模块