简体   繁体   中英

When my Vue app doesn't render on IE11, how can I display a disclaimer screen?

my app was developed in Vue and currently it doesn't work great in IE11 and old edge, I can render a "please update your browser screen" on edge because the app will load somewhat, however IE11 just shows a blank screen.

How can I check to see if the user is on IE11 and then just render a plain HTML/CSS page that asks them to update their browser?

I have met this kind of issue before. I detect the browser version and if IE then render some messages you need. If not IE then render the vue app.

I use JavaScript in public/index.html to detect browser, the code is like below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM