doctor-mail/web-app/browserCheck.js

59 lines
2.1 KiB
JavaScript
Raw Normal View History

2025-02-17 16:02:13 +08:00
// browserCheck.js
// 检查浏览器版本的函数
function checkBrowserVersion() {
const userAgent = navigator.userAgent;
const chromeMatch = userAgent.match(/Chrome\/(\d+)/);
if (chromeMatch) {
const chromeVersion = parseInt(chromeMatch[1], 10);
if (chromeVersion < 80) {
showMustDownloadPrompt();
} else if (chromeVersion < 100) {
showUpdatePrompt();
}
} else if (userAgent.includes("MSIE") || userAgent.includes("Trident/")) {
showUpdatePrompt();
}
}
function showUpdatePrompt() {
const result = window.confirm(
"检测到您的浏览器版本较低,建议更新到最新版本以获得更好的体验。是否下载新版浏览器?"
);
if (result) {
// 提供下载链接
const link = document.createElement("a"); // 创建一个链接元素
link.href = "/chrome.exe"; // 替换为您在 public 目录中的安装包路径
link.download = "chrome.exe"; // 设置下载文件名
document.body.appendChild(link); // 将链接添加到文档中
link.click(); // 模拟点击下载
document.body.removeChild(link); // 下载后移除链接
// 打开预览地址
// window.open(previewUrl, "_blank"); // 在新标签页中打开预览地址
}
}
function showMustDownloadPrompt() {
const previewUrl = "http://192.168.139.239:8095"; // 获取预览地址
const result = window.confirm(
"检测到您的浏览器版本过低,可能无法正常使用网站功能。是否立即下载推荐浏览器并打开预览地址进行预览?"
);
if (result) {
// 提供下载链接
const link = document.createElement("a"); // 创建一个链接元素
link.href = "/chrome.exe"; // 替换为您在 public 目录中的安装包路径
link.download = "chrome.exe"; // 设置下载文件名
document.body.appendChild(link); // 将链接添加到文档中
link.click(); // 模拟点击下载
document.body.removeChild(link); // 下载后移除链接
// 打开预览地址
window.location.href = previewUrl; // 在新标签页中打开预览地址
}
}
// 在页面加载时检查浏览器版本
window.onload = checkBrowserVersion;