0

I want to block access to my site to all versions of internet 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
}
ADyson
  • 57,178
  • 14
  • 51
  • 63
Rocstar
  • 1,427
  • 3
  • 23
  • 41
  • 1
    you know that user agents can easily be spoofed? Most ordinary users wouldn't do it, but anyone knowledgeable, or who knows how to use a search engine to find out, would be able to bypass this easily. Besides, why do you want to block (the old) Edge? Have you managed to build something using features it doesn't support? Why not implement a fallback instead? Otherwise you're just excluding users potentially, and for most sites that's a bad thing (because they want customers / visitors). – ADyson Oct 09 '20 at 09:09
  • Thank you ! This solution is intended to be used internally (intranet site) and to force a change of browser, I sometimes receive complaints because some JS functionality bug or that the CSS is not good, but this happens most of the time from their browser (I don't have my hands on it, there are several entities such as the United States, Spain, Germany, etc.) – Rocstar Oct 09 '20 at 09:17
  • Well if this is a corporate environment, then surely you can just make sure using Group Policy that everyone's Windows 10 is upgraded so that it includes the latest (Chromium) version of Edge? Then the problem goes away. – ADyson Oct 09 '20 at 09:20
  • Alas, I only control my region ... I just deployed the site elsewhere, specifying that I should drop IE .. on the first screen telling me that the CSS is broken I see that it is IE ... So you might as well get straight to the point, giving an error message with explanations – Rocstar Oct 09 '20 at 09:26
  • 1
    I see. The only thing you can do is experiment with the two versions of Edge - use them to send requests to a test page, and see if their user-agent strings are different or not. If they're not different, then you can't tell them apart on the server-side. In that scenario, as an alternative you _might_ be able to embed a little bit of JS in the site which can tell you what the browser supports (or even which browser it is) when a page loads, and then pop up a message at that point to the user saying they need to use a different browser. – ADyson Oct 09 '20 at 09:32
  • 1
    But I don't know the specifics of how that's done, it's not an issue I've ever had to contend with personally. So unless anyone else pops up on here who knows, you might need to spend a little bit of time on research, and if that fails, ask a different question about that subject on here with relevant tags. – ADyson Oct 09 '20 at 09:33
  • Indeed, I thought I had a quick answer, thank you in any case for your advice – Rocstar Oct 09 '20 at 09:46
  • @Rocstar, Does checking the user agent using the code example I shared in the answer helped you to identify the IE and legacy Edge? If yes and if you think it can help you to solve the issue then I suggest you please mark the helpful suggestion as an accepted answer. It can help other community members in the future in similar kinds of issues. Thanks for your understanding. – Deepak-MSFT Oct 29 '20 at 05:26

1 Answers1

0

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:

enter image description here

Referenced answer:

How can I detect Internet Explorer (IE) and Microsoft Edge using JavaScript?

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

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19