-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
108 lines (106 loc) · 4.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name='apple-itunes-app' content='app-id=1286623506' aria-hidden="true" hidden="true">
<title>Open App - Vue</title>
</head>
<body>
<h3>手机判断并安装某App</h3>
<div id="app">
<a v-show="android" href="com.commoditiesinchina.cstores://app" id="btnopenandroid">立即打开{{ title }}</a>
<a v-show="ios" href="KstoreApp://" id="btnopenios">立即打开{{ title }}</a>
</div>
<script src="/bower_components/vue/dist/vue.min.js"></script>
<script>
var os = function () {
var ua = navigator.userAgent,
isWeixin = /(?:micromessenger)/.test(ua.toLowerCase()),
isQB = /(?:MQQBrowser|QQ)/.test(ua),
isWindowsPhone = /(?:Windows Phone)/.test(ua),
isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
isAndroid = /(?:Android)/.test(ua),
isFireFox = /(?:Firefox)/.test(ua),
isChrome = /(?:Chrome|CriOS)/.test(ua),
isIpad = /(?:iPad|PlayBook)/.test(ua),
isTablet = /(?:iPad|PlayBook)/.test(ua) || (isFireFox && /(?:Tablet)/.test(ua)),
isSafari = /(?:Safari)/.test(ua),
isIPhone = /(?:iPhone)/.test(ua) && !isTablet,
isOpen = /(?:Opera Mini)/.test(ua),
isUC = /(?:UCWEB|UCBrowser)/.test(ua),
isPc = !isIPhone && !isAndroid && !isSymbian;
return {
isWeixin: isWeixin,
isQB: isQB,
isTablet: isTablet,
isIPhone: isIPhone,
isAndroid: isAndroid,
isPc: isPc,
isOpen: isOpen,
isUC: isUC,
isIpad: isIpad
};
}();
new Vue({
el:'#app',
data:{
appurl:'',
appstore:'',
title:'',
android:false,
ios:false
},
created () {
var _self = this;
if(os.isAndroid){
console.log(1)
_self.title = 'android';
_self.android = true;
_self.appurl = 'com.commoditiesinchina.cstores://app';
_self.appstore = 'https://play.google.com/store/apps/details?id=com.commoditiesinchina.cstores';
}
if(os.isIPhone || os.isIpad){
console.log(2)
_self.title = 'ios';
_self.ios = true;
_self.appurl = 'KstoreApp://';
_self.appstore = 'https://itunes.apple.com/cn/app/cstrores/id1286623506';
}
},
methods:{
openapp(){
var _self = this;
var clickedAt = new Date();
setTimeout(function(){
if (new Date() - clickedAt < 2000){
window.location = _self.appstore;
}
}, 500);
}
}
})
var appstore = '';
// 为 a标签 绑定事件,如果在500ms内,没有解析到协议,那么就会跳转到下载链接
if(os.isAndroid){
appstore = 'https://play.google.com/store/apps/details?id=com.commoditiesinchina.cstores';
}
if(os.isIPhone || os.isIpad){
appstore = "https://itunes.apple.com/cn/app/cstrores/id1286623506";
}
function applink(fail){
return function(){
var clickedAt = new Date();
setTimeout(function(){
if (((new Date()) - clickedAt) < 2000){
window.location = fail;
}
}, 500);
};
}
document.getElementById('btnopenios').onclick = applink(appstore);
document.getElementById('btnopenandroid').onclick = applink(appstore);
</script>
</body>
</html>