如果 IE11 或 IE10,浏览器重定向 Vuetify Vue.js 应用程序

Browser redirect a Vuetify Vue.js app if IE11 or IE10

我在使用 Vuetify 和 IE11 时遇到了噩梦,我想重定向到一个基本的 HTML 页面,该页面显示不支持 IE 11 或 IE 10。我在大学工作,IE11 仍然是标准,因为它与我们的电子病历系统紧密集成。 IE11 是标准,因此如果在电子邮件中发送 link,IE11 将打开。我在 app.vue 页面

中尝试过
           var compatibleBrowser = typeof Object["__defineSetter__"] === "function";
           if (compatibleBrowser == false) {
           alert("Sorry, this is not a compatible browser.");
           }

      if ((browser=="msie") && (version>=4)) {
      if (browser=="opera"||"chrome"||"safari"||"firefox") {
      location.replace("mobile_demo.php");
      }
     else {
     location.replace("full_demo.php");
     }
     }

Whosebug 和 Codepen 都有一些识别代码,我想将其添加到 vue 应用程序中。问题是我不断收到 SCRIPT5009:'Symbol' 未定义文件:vuetify.js,行:19641,列:1 而且我似乎无法用 polyfill 修复它。

所以下一个最好的办法就是重定向

您可以检测浏览器版本,如果 IE 会呈现您需要的一些消息。如果不是 IE,则渲染 vue 应用程序。

我在public/index.html中使用JavaScript检测浏览器,代码如下:

<!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>