- 方法一
- 说明: 当点击打开某一app按钮时, 判断手机是否安装此款app, 有的话就直接打开app首页, 没安装app就直接跳转对应的app store.
var ua = window.navigator.userAgent.toLowerCase();
var url_ios = 'weixin://';
var url_ios_download = 'http://www.wjtr.com/download/index.html';
var url_android = 'weixin://';
var url_android_download = 'https://itunes.apple.com/cn/app/jian-kang-mao-rang-yun-dong/id966436668?mt=8';
console.log(url_android);
//通过window.navigator.userAgent来判断当前设备是IOS还是Android。
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
window.location.href='downLoadForPhone';
}else{//非微信浏览器
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
var loadTime = new Date();
location.href = url_ios;
setTimeout(function(){
var outTime = new Date()
if(outTime - loadTime > 800){
location.href = url_ios_download;
}
},1000)
}else if (navigator.userAgent.match(/android/i)) {
var loadTime = new Date();
location.href = url_android;
setTimeout(function(){
location.href = url_android_download;
},200)
}
}
function openApp(){
var ua = window.navigator.userAgent.toLowerCase();
//微信
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
window.location.href='downLoadForPhone';
}else{//非微信浏览器
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
var loadDateTime = new Date();
window.setTimeout(function() {
var timeOutDateTime = new Date();
if (timeOutDateTime - loadDateTime < 5000) {
window.location = "";//ios下载地址
} else {
window.close();
}
},2000);
window.location = "schema://";
}else if (navigator.userAgent.match(/android/i)) {
var state = null;
try {
window.location = 'weixin://';
$('#btn2').hide();
setTimeout(function(){
window.location= "https://itunes.apple.com/cn/app/jian-kang-mao-rang-yun-dong/id966436668?mt=8"; //android下载地址
},500);
} catch(e) {}
}
}
}