做了一个浏览器自动唤起app功能,代码在其他浏览器上都可以自动唤起app,uc浏览器却不能自动唤起只能通过手动点击去唤起事件,相关代码如下
// 请把代码文本粘贴到下方(请勿用图片代替代码)
html:
<div class="openApp animated bounceInUp">页面尝试跳转到“xxx”应用,是否允许?<span>查看</span></div>
javascript:
var BASE_API = 'http://xxx.xxx.xxx.com';
var API_URL = '';
var ticketId = getQueryString('ticket');
var res = '';
var isBind = '';
var Id = '';
var name = '';
var thirdId = '';
var locationHref = window.location.href;
if(ticketId == null || ticketId == ''){
console.log("ticket为空");
}
//
getJumoInfo(ticketId);
var lastLink = ''; // 最终的跳转地址
var application = '';
var studnetAppLink ='';
var teacherAppLink ='';
function getJumoInfo(ticketId){
var os = system().os;
.......
$.get(..... , function(res) {
var response = {};
// console.log(res);
if(response.status==200){
/*中间一大堆回调返回值代码*/
........
//自动唤起app
document.getElementById('openApp').click();
}
}else{
alert("二维码已过期,请重新生成!");
}
});
}
function system() {
var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
return {
os: isAndroid ? 'android' : (isIOS ? 'ios' : null)
}
}
function appJump(src) {
// alert(navigator.userAgent);
if (src) {
var ifr = document.createElement('iframe');
ifr.src = src;
ifr.style.display = 'none';
document.body.appendChild(ifr);
alert(src);
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > (300 + 2)) {
return; //如果不存在则不做任何操作,留在当前页面
}
window.location.href = src; //如果存在app则跳转到指定app的页面
}, 300);
}
}
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return decodeURI(r[2]);
return null;
}
function submitFn() {
//判断浏览器
var os = system().os;
if(!lastLink) return;
var link = lastLink;
appJump(link);
}
现在的问题,即使本地已经有app,uc浏览器也不会自动唤起,需要手动点击绑定在div上的onclick事件才能触发唤起app,其他浏览器却可以直接唤起,试了n种方法都没找到问题所在,求个大神指导下问题出在哪里
你是用 url scheme 去唤醒的吗 uc 会在你的scheme 前面加上http://