javascript - 当我的 Vue 应用程序无法在 IE11 上呈现时,如何显示免责声明屏幕?

标签 javascript vue.js internet-explorer-11

我的应用程序是在 Vue 中开发的,目前它在 IE11 和旧 Edge 中效果不佳,我可以在 Edge 上呈现“请更新您的浏览器屏幕”,因为该应用程序会加载一些,但是 IE11 只是显示一个空白屏幕。
如何检查用户是否在 IE11 上,然后只呈现一个要求他们更新浏览器的纯 HTML/CSS 页面?

最佳答案

我以前遇到过这种问题。我检测浏览器版本,如果 IE 然后呈现您需要的一些消息。如果不是 IE,则渲染 vue 应用程序。
我在 中使用 JavaScript公共(public)/index.html 检测浏览器,代码如下:

<!DOCTYPE html>
<html lang="en">
 <head>
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width,initial-scale=1.0">
   <link rel="icon" href="<%= BASE_URL %>favicon.ico">
   <title>my-vue-app</title>
 </head>
 <body>
   <noscript>
     <strong>We're sorry but my-vue-app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
   </noscript>
   <!-- built files will be auto injected -->
   <script type="text/javascript">
     function get_browser() {
       var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
       if (/trident/i.test(M[1])) {
         tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
         return { name: 'IE', version: (tem[1] || '') };
       }
       if (M[1] === 'Chrome') {
         tem = ua.match(/\bOPR\/(\d+)/)
         if (tem != null) { return { name: 'Opera', version: tem[1] }; }
       }
       if (window.navigator.userAgent.indexOf("Edge") > -1) {
         tem = ua.match(/\Edge\/(\d+)/)
         if (tem != null) { return { name: 'Edge', version: tem[1] }; }      
       }
       M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
       if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]); }
       return {
         name: M[0],
         version: +M[1]
       };
     }

     var browser = get_browser()
     var isSupported = isSupported(browser);

     function isSupported(browser) {
       var supported = false;
       if (browser.name === "Chrome" && browser.version >= 48) {
         supported = true;
       } else if ((browser.name === "MSIE" || browser.name === "IE") && browser.version <= 11) {
         supported = false;
       } else if (browser.name === "Edge") {
         supported = true;
       }
       return supported;
     }

     if (!isSupported) {
       //render unsupported message
       document.write("<h1>The app is not supported in IE. Please use other browsers!</h1>");
     }
     else{
       //render app
       var elem = document.createElement("div");
       elem.setAttribute("id", "app")
       document.body.appendChild(elem);
     }
   </script>
 </body>
</html>

关于javascript - 当我的 Vue 应用程序无法在 IE11 上呈现时,如何显示免责声明屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62938071/

相关文章:

javascript - 在新选项卡中打开由 [innerHTML] 绑定(bind)的 Angular 6 链接

mysql - Laravel 5 插入带有外键错误的行

javascript - 刷新动态路由时,Nuxt 应用程序返回 404(Tomcat 服务器)

c# - 无 Cookie session

javascript - IE 11 中的 &lt;input type ="file"> 属性未正确显示

javascript - Vee-validate 独立验证来自父级的组件,无需使用 EventBus

javascript - 页面闲置一段时间后,为什么没有数据传给客户端?

javascript - session 模型-创建日程方法(Sequelize)

vue.js - 观察变量变化不起作用

jsf - b :inputText type "date" not working on IE 11 and Firefox 47. 0