简体   繁体   中英

How to block all IE and Microsoft Edge other than Chromium

I want to block access to my site to all versions of inte.net explorer and old versions of Microsoft Edge ( all except Edge Chromimum )

I started with that, thanks to an old post, but I can't find how to block Edge without blocking Edge chromium:

if(preg_match('/(?i)(msie [0-9]+)|(Trident\/[0-9]+)/', $_SERVER['HTTP_USER_AGENT'])) {
  // Error message
}
else {
  // Login form
}

I suggest you try to check the substring of the user agent may help to identify the IE and Edge legacy browser. Then if it is an IE or Edge legacy browser then you can show a message to the users to use the MS Edge Chromium browser. If it is any other browser then it will let users visit the site.

Sample code:

<!doctype html>
<html>
   <head>
   </head>
   <body>
      <div id="info"></div>
      <script>
         function detectIE() {
           var ua = window.navigator.userAgent;
         
           var msie = ua.indexOf('MSIE ');
           if (msie > 0) {
            
             return "IE " + parseInt( ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
           }
         
           var trident = ua.indexOf('Trident/');
           if (trident > 0) {
            
             var rv = ua.indexOf('rv:');
             return "IE " + parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
           }
         
           var edge = ua.indexOf('Edge/');
           if (edge > 0) {
            
             return "Edge " + parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
           }
         
           // other browser
           return "false";
         }
         var result=detectIE();
         if (result=="false")
         {
            document.getElementById("info").innerHTML +="<h2>Welcome to the site...</h2>";
         }
         else
         {
            document.getElementById("info").innerHTML += "<h2>Dear user you are using " + result + " This browser is not supported by this site. Kindly use MS Edge Chromium browser...</h2>";
                //console.log(result);
         }
         
      </script>
   </body>
</html>

Output:

在此处输入图像描述

Referenced answer:

How can I detect Inte.net Explorer (IE) and Microsoft Edge using JavaScript?

Further, you can modify the code sample as per your own requirements.

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