H5唤醒app,不完全兼容

---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方式可自行了解。

上一篇:2440nandflash启动过程再学习


下一篇:Bootstrap~大叔封装的弹层