Home > Enterprise >  JavaScript code detects IE 10 as supported version instead of as out of date
JavaScript code detects IE 10 as supported version instead of as out of date

Time:03-23

The code below generates alert "Your browser is supported" even if the version is IE 10. It works perfectly with browsers such as IE 9, 8 and 7. I need to ensure only version IE 11 is allowed. Is there really anything wrong with the code?

<script type="text/javascript">
    jQuery(document).ready(function($){
    // true on IE11
    // false on Edge and other IEs/browsers.        filters.hide();
    // Allow only IE 11 and other browsers like Chrome, Safar, firefox so on,
    // but never allow lower versions of IE starting IE 10.
    var div = document.createElement("div");
    div.innerHTML = "<!--[if lt IE 11]><i></i><![endif]-->";
    var isIeLessThan11 = (div.getElementsByTagName("i").length == 1);
    if (isIeLessThan11) {
      alert("Your web browser is out of date. Please complete this form using an approved browser, such as Edge, Chrome, Safari, or Firefox.");
    } else {
      alert("Your browser is supported");
    }
  });
</script>

CodePudding user response:

According to wikipedia, conditional comments are not supported in IE10 and above. https://en.m.wikipedia.org/wiki/Conditional_comment

  • Related