Redirecting away from Internet Explorer

Here is a bit of script to detect if a user is on Internet and Explorer and then automatically redirects them to Edge if they are. Place it in the site header and it will take the user from the page they are on in IE to the same page in Edge.

This function was helpful for me as my site heavily used grids and flex designs which IE doesn’t support making our site mostly unusable in IE. Noticing that sites like Twitter and Apple will just automatically open Edge and take you to their site if you try using IE I hunted around for some script that will do the same thing but only found examples that did part of the job. However, I was able to modify what I found to the script below which I implemented and it has been working successfully.

<script>
    function FindIE() {

      var ua = window.navigator.userAgent;
      var msie = ua.indexOf("MSIE ");
      var site = "microsoft-edge:" + window.location.href;

      if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) 
      {     location.replace(site);
          
      }
      else  
      {
        console.log("Welcome");
      }

      return false;
      }
      FindIE()
</script>