HTML 下载APP 页面 - 支持多语言
支持多语言
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>App Download</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #6e8efb, #a777e3);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
color: #333;
font-size: 16px;
}
.container {
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
width: 100%;
max-width: 600px;
padding: 30px;
text-align: center;
}
.logo {
margin-bottom: 20px;
}
.logo h1 {
font-size: 2.5rem;
color: #6e8efb;
margin-bottom: 10px;
}
.logo p {
color: #777;
font-size: 1.1rem;
}
.device-info {
background: #f8f9fa;
border-radius: 12px;
padding: 15px;
margin: 20px 0;
text-align: left;
}
.device-info h3 {
color: #6e8efb;
margin-bottom: 10px;
display: flex;
align-items: center;
}
.device-info h3 i {
margin-right: 10px;
}
.info-item {
margin: 8px 0;
display: flex;
}
.info-label {
font-weight: 600;
min-width: 120px;
color: #555;
}
.app-details {
margin: 25px 0;
padding: 20px;
background: #e9f7ff;
border-radius: 12px;
border-left: 5px solid #6e8efb;
}
.app-icon {
width: 80px;
height: 80px;
background: #6e8efb;
border-radius: 20px;
margin: 0 auto 15px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 2rem;
font-weight: bold;
}
.app-name {
font-size: 1.8rem;
color: #333;
margin-bottom: 10px;
}
.download-status {
font-size: 1.2rem;
color: #28a745;
margin: 15px 0;
font-weight: 500;
}
.download-btn {
display: inline-block;
background: #6e8efb;
color: white;
padding: 14px 35px;
border-radius: 50px;
text-decoration: none;
font-weight: 600;
font-size: 1.1rem;
margin: 15px 0;
transition: all 0.3s ease;
border: none;
cursor: pointer;
box-shadow: 0 4px 15px rgba(110, 142, 251, 0.4);
}
.download-btn:hover {
background: #5a7df9;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(110, 142, 251, 0.6);
}
.loading {
display: flex;
justify-content: center;
margin: 20px 0;
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid rgba(110, 142, 251, 0.3);
border-radius: 50%;
border-top-color: #6e8efb;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.footer {
margin-top: 25px;
color: #777;
font-size: 0.9rem;
}
.footer a {
color: #6e8efb;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
body {
padding: 15px;
font-size: 14px;
}
.container {
padding: 20px;
}
.logo h1 {
font-size: 2rem;
}
.app-name {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<div class="logo">
<h1 id="title">App Download</h1>
<p id="subtitle">Get the latest version of our application</p>
</div>
<div class="device-info">
<h3><i>📱</i> <span id="device-info-title">Device Information</span></h3>
<div class="info-item">
<span class="info-label" id="user-agent-label">User Agent:</span>
<span id="user-agent"></span>
</div>
<div class="info-item">
<span class="info-label" id="language-label">Language:</span>
<span id="language"></span>
</div>
<div class="info-item">
<span class="info-label" id="os-label">Operating System:</span>
<span id="operating-system"></span>
</div>
</div>
<div class="app-details">
<div class="app-icon" id="app-icon">APP</div>
<div class="app-name" id="app-name">Application</div>
<div class="download-status" id="download-status">Preparing download...</div>
<div class="loading">
<div class="spinner"></div>
</div>
</div>
<div class="footer">
<p id="manual-download-text">If download doesn't start automatically, <a href="#" id="manual-link">click here</a></p>
<p id="copyright">© 2023 App Download Center. All rights reserved.</p>
</div>
</div>
<script>
// 获取用户代理和语言信息
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
var language = navigator.language;
// 多语言支持
var translations = {
"en": {
"title": "App Download",
"subtitle": "Get the latest version of our application",
"device-info-title": "Device Information",
"user-agent-label": "User Agent:",
"language-label": "Language:",
"os-label": "Operating System:",
"preparing-download": "Preparing download...",
"use-browser": "Please use a browser to download",
"mobile-download": "Mobile download detected",
"redirecting": "Redirecting to download...",
"checking-version": "Checking for latest version...",
"downloading": "Downloading the latest version...",
"manual-download": "If download doesn't start automatically, ",
"click-here": "click here",
"copyright": "© 2023 App Download Center. All rights reserved."
},
"zh-CN": {
"title": "应用下载",
"subtitle": "获取我们应用的最新版本",
"device-info-title": "设备信息",
"user-agent-label": "用户代理:",
"language-label": "语言:",
"os-label": "操作系统:",
"preparing-download": "准备下载...",
"use-browser": "请使用浏览器进行下载",
"mobile-download": "检测到移动设备下载",
"redirecting": "正在跳转到下载页面...",
"checking-version": "正在检查最新版本...",
"downloading": "正在下载最新版本...",
"manual-download": "如果下载没有自动开始,请",
"click-here": "点击这里",
"copyright": "© 2023 应用下载中心。保留所有权利。"
}
};
// 设置语言
var lang = language === "zh-CN" ? "zh-CN" : "en";
// 应用翻译
function applyTranslations() {
document.getElementById("title").textContent = translations[lang].title;
document.getElementById("subtitle").textContent = translations[lang].subtitle;
document.getElementById("device-info-title").textContent = translations[lang]["device-info-title"];
document.getElementById("user-agent-label").textContent = translations[lang]["user-agent-label"];
document.getElementById("language-label").textContent = translations[lang]["language-label"];
document.getElementById("os-label").textContent = translations[lang]["os-label"];
document.getElementById("manual-download-text").innerHTML = translations[lang]["manual-download"] +
'<a href="#" id="manual-link">' + translations[lang]["click-here"] + '</a>';
document.getElementById("copyright").textContent = translations[lang].copyright;
}
// 显示设备信息
document.getElementById("user-agent").textContent = userAgent;
document.getElementById("language").textContent = language;
// 检测移动操作系统函数
function detectMobileOS() {
if (/android/i.test(userAgent)) {
return "Android";
}
if (/\(i[^;]+;( U;)? CPU.+Mac OS X/.test(userAgent)) {
return "iOS";
}
if (/windows/i.test(userAgent)) {
return "Windows";
}
return "Unknown";
}
var mobileOS = detectMobileOS();
document.getElementById("operating-system").textContent = mobileOS;
// 获取URL参数
const queryString = window.location.search.substring(1);
var type = queryString.split('=')[1];
var redirect_url = "";
var appName = "";
var appIconText = "";
// 设置应用信息
if (type == '1') {
appName = "APP 1";
appIconText = "A1";
} else if (type == '2') {
appName = "APP 2";
appIconText = "A2";
}
// 更新UI
document.getElementById("app-name").textContent = appName;
document.getElementById("app-icon").textContent = appIconText;
if (!mobileOS) {
document.getElementById("download-status").textContent = translations[lang]["use-browser"];
} else {
document.getElementById("download-status").textContent = translations[lang]["mobile-download"];
}
// 应用下载逻辑
if (type == '1') {
if (mobileOS == "iOS") {
redirect_url = "https://apps.apple.com/app/XXX";
} else {
if (language == "zh-CN") {
getLastVersion("a1");
} else {
redirect_url = "https://play.google.com/store/apps/details?id=XXX";
}
}
} else if (type == '2') {
if (mobileOS == "iOS") {
redirect_url = "https://apps.apple.com/app/XXX";
} else {
if (language == "zh-CN") {
getLastVersion("a2");
} else {
redirect_url = "https://play.google.com/store/apps/details?id=XXX";
}
}
}
// 设置手动下载链接
document.getElementById("manual-link").href = redirect_url;
// 重定向逻辑
if (redirect_url) {
document.getElementById("download-status").textContent = translations[lang].redirecting;
setTimeout(function() {
location.href = redirect_url;
}, 2000);
}
// 获取最新版本函数
function getLastVersion(typeId) {
var obj = {};
obj.ApkTypeId = typeId;
$.ajax({
url: "http://www.vipsoft.com.cn/",
type: 'post',
dataType: 'json',
contentType: "application/json;charset=utf-8",
data: JSON.stringify(obj),
beforeSend: function() {
document.getElementById("download-status").textContent = translations[lang]["checking-version"];
},
success: function(data) {
document.getElementById("download-status").textContent = translations[lang].downloading;
document.getElementById("manual-link").href = redirect_url;
setTimeout(function() {
location.href = redirect_url;
}, 1500);
},
error: function(XmlHttpRequest, textStatus, errorThrown) {
document.getElementById("download-status").textContent = "Error: " + textStatus + ". Please try again later.";
document.getElementById("download-status").style.color = "#dc3545";
}
});
}
// 应用翻译
applyTranslations();
</script>
</body>
</html>

本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/19072437
浙公网安备 33010602011771号