// browserCheck.js // 检测浏览器是否支持 ES6 function supportsES6() { try { // 尝试使用一些 ES6 特性 new Function("(a = 0) => a"); let test = 0; const testConst = 0; class TestClass {} Promise.resolve(); return true; } catch (e) { return false; } } // 检查浏览器版本的函数 function checkBrowserVersion() { const userAgent = navigator.userAgent; const chromeMatch = userAgent.match(/Chrome\/(\d+)/); const firefoxMatch = userAgent.match(/Firefox\/(\d+)/); if (chromeMatch) { const chromeVersion = parseInt(chromeMatch[1], 10); if (chromeVersion < 80) { showMustDownloadPrompt(); } else if (chromeVersion < 100) { showUpdatePrompt(); } } else if (firefoxMatch) { const firefoxVersion = parseInt(firefoxMatch[1], 10); if (firefoxVersion < 70) { showMustDownloadPrompt(); } else if (firefoxVersion < 90) { showUpdatePrompt(); } } else if (!supportsES6()) { showMustDownloadPrompt(); } 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;