-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex-js.html
67 lines (67 loc) · 2.95 KB
/
index-js.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
<!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 - js</title>
</head>
<body>
<h3>手机判断并安装某App</h3>
<a href="KstoreApp://" id="btnopenios" style="display:none">立即打开1</a>
<a href="com.commoditiesinchina.cstores://app" id="btnopenandroid" style="display:none">立即打开2</a>
<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
};
}();
var appstore = '';
// 为 a标签 绑定事件,如果在500ms内,没有解析到协议,那么就会跳转到下载链接
if(os.isAndroid){
document.getElementById("btnopenandroid").style="display:inline";
appstore = 'https://play.google.com/store/apps/details?id=com.commoditiesinchina.cstores';
}
if(os.isIPhone || os.isIpad){
document.getElementById("btnopenios").style="display:inline";
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>