Repository navigation
Expand file tree
/
Copy pathIntent.html
More file actions
108 lines (95 loc) · 3.83 KB
/
Copy pathIntent.html
File metadata and controls
108 lines (95 loc) · 3.83 KB
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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>正在打开…</title>
<style>
body {
margin: 0; height: 100vh; display: flex; flex-direction: column;
align-items: center; justify-content: center;
font-family: -apple-system, "PingFang SC", sans-serif;
color: #666; background: #fafafa; padding: 20px; box-sizing: border-box;
}
#msg {
text-align: center; line-height: 1.6; font-size: 16px;
margin-bottom: 20px; white-space: pre-line;
}
#actions {
display: none; /* 默认隐藏,1.5秒后统一显示 */
flex-direction: column; gap: 12px; width: 100%; max-width: 320px;
}
button {
padding: 16px; font-size: 16px; border: none; border-radius: 12px;
cursor: pointer; font-weight: 600; touch-action: manipulation;
transition: transform 0.1s, opacity 0.2s;
}
button:active { transform: scale(0.97); opacity: 0.9; }
#retryBtn { background: #1677ff; color: #fff; box-shadow: 0 4px 12px rgba(22,119,255,0.3); }
#downloadBtn { background: #e8f3ff; color: #1677ff; box-shadow: 0 4px 12px rgba(22,119,255,0.1); }
</style>
</head>
<body>
<div id="msg">正在打开应用…</div>
<div id="actions">
<button id="retryBtn">重新打开</button>
<button id="downloadBtn">下载 Via 浏览器</button>
</div>
<script>
(function () {
var msg = document.getElementById('msg');
var actions = document.getElementById('actions');
var retryBtn = document.getElementById('retryBtn');
var downloadBtn = document.getElementById('downloadBtn');
// ================= 1. 解析参数 =================
var raw = window.location.search.substring(1);
if (!raw) { showError('缺少参数'); return; }
var value = raw.replace(/^=/, '');
var slash = value.indexOf('/');
if (slash < 0) { showError('参数格式错误,应为 包名/活动全路径'); return; }
var pkg = value.substring(0, slash);
var activity = value.substring(slash + 1);
var component = pkg + '/' + activity;
// ================= 2. 拼接 intent:// =================
var intentUrl =
'intent://open/#Intent;' +
'action=android.intent.action.MAIN;' +
'category=android.intent.category.LAUNCHER;' +
'category=android.intent.category.BROWSABLE;' +
'package=' + pkg + ';' +
'component=' + component + ';' +
'end';
// ================= 3. 跳转触发函数 =================
function launchApp() {
// 仅使用 iframe 触发。Via 会弹窗让用户确认,Chrome 会被静默拦截。
// 无论哪种情况,都不会导致当前页面发生跳转。
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = intentUrl;
document.body.appendChild(iframe);
}
// ================= 4. 按钮事件绑定 =================
retryBtn.addEventListener('click', function () {
launchApp(); // 再次触发,界面保持不变
});
downloadBtn.addEventListener('click', function () {
window.location.href = 'https://www.viayoo.com';
});
// ================= 5. 初始启动与固定界面 =================
function showError(text) {
msg.textContent = text;
actions.style.display = 'none';
}
// 首次自动尝试触发
launchApp();
// 1.5 秒后,无论上面的跳转是否成功,统一显示最终的说明界面。
setTimeout(function () {
msg.textContent = '如果未能自动打开,说明当前浏览器限制了网页直接启动外部应用。\n\n' +
'部分浏览器(如 Chrome、Edge 等)出于安全策略,可能会拦截此请求,甚至跳转至系统的应用商店(Google Play)。\n\n' +
'Via 浏览器支持此功能,您可以点击下方按钮重试,需要额外点击弹窗的确认,或下载 Via 浏览器后重新访问本链接。';
actions.style.display = 'flex';
}, 1500);
})();
</script>
</body>
</html>