<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>战功App</title>
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
color: #a9b1b3;
font-size: 14px;
background-color: #fff;
-webkit-font-smoothing: antialiased;
}
#weixin {
width: 100%;
height: 100%;
background-image: url(./image/weixin.png);
background-size: 100% 100%;/*按比例缩放*/
background-repeat: no-repeat;/*还有repeat-x,y等*/
}
#pc {
width: 100%;
height: 100%;
background-image: url(./image/pc.png);
background-size: 100% 100%;/*按比例缩放*/
background-repeat: no-repeat;/*还有repeat-x,y等*/
}
</style>
</head>
<body>
<div style="height: 100%;width: 100%;">
<div id="weixin">
</div>
<div id="pc"></div>
</div>
<script>
var type_phone = 1101;
var playload = '';
var browser = {
versions: function () {
var u = navigator.userAgent, app = navigator.appVersion;
return { //移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if (browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面
var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
if (browser.versions.ios) {
//是否在IOS浏览器打开
console.log('是否在IOS浏览器打开:>> ');
type_phone = 1102;
// 1101安卓1102ios
let url = 'http://****/trainning/appUpdate/newestApkUrl?type='+type_phone
getData(url);
}
if(browser.versions.android){
//是否在安卓浏览器打开
console.log('是否在安卓浏览器打开:>> ');
document.getElementById('weixin').style.display="none";
document.getElementById('pc').style.display="none";
type_phone = 1101;
// 1101安卓1102ios
let url = 'http://****/trainning/appUpdate/newestApkUrl?type='+type_phone
getData(url);
if (ua.match(/MicroMessenger/i) == "micromessenger") {
//在微信中打开
console.log('在微信中打开:>> ');
document.getElementById('weixin').style.display="block";
document.getElementById('pc').style.display="none";
}else {
document.getElementById('weixin').style.display="none";
document.getElementById('pc').style.display="block";
type_phone = 1101;
// 1101安卓1102ios
let url = 'http://****/trainning/appUpdate/newestApkUrl?type='+type_phone
getData(url);
}
}
} else {
//否则就是PC浏览器打开
console.log('否则就是PC浏览器打开:>> ');
document.getElementById('weixin').style.display="none";
document.getElementById('pc').style.display="block";
type_phone = 1101;
// 1101安卓1102ios
let url = 'http://****/trainning/appUpdate/newestApkUrl?type='+type_phone
getData(url);
}
function getData(url){
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', url, true);
httpRequest.send();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var json = httpRequest.responseText;
let data = JSON.parse(json).data;
console.log('object :>> ', json);
console.log(data);
playload = data.downloadUrl;
// alert('请求成功',playload)
}
};
}
document.getElementById('pc').addEventListener("click", function () {
console.log('点击')
downloadApk()
})
function downloadApk() {
location.href = playload;
}
</script>
</body>
</html>