Detect lower versions of Internet Explorer in mvc 4

4.6k views Asked by At

I just created mvc 4 application. In that application I want to show alert,if user open this web application using Internet Explorer 6,7 and 8

This is the code I put top of "_Layout.cshtml" file

@if ((Request.Browser.Browser == "IE") & ((Request.Browser.Version == "8.0") | (Request.Browser.Version == "7.0") | (Request.Browser.Version == "6.0")))
{
   <script type='text/javascript'>

      alert("You're using older version of Internet Explorer")

  </script>
}

But this is not checking internet explorer version , it gives me pop up for almost all the versions of Internet Explorer ( Edge(11) , 10 , 9 , 8 , 7, 6 )

How can I filter those versions separately

2

There are 2 answers

4
Manoz On

Try this-

  @if (Request.Browser.Browser == "IE" && Convert.ToDouble(Request.Browser.Version) < 7.0)
        {   
            <script type='text/javascript'>

                alert("You're using older version of Internet Explorer")

            </script>
        }

Edit-

This checks if current version of IE is lower than 7.0, You can change the version number accordingly.

Edit 2- I just realized my browser was named as InternetExplorer, So I changed following-

@if (Request.Browser.Browser == "InternetExplorer" && Convert.ToDouble(Request.Browser.Version) < 7.0)
        {   
            <script type='text/javascript'>

                alert("version is not lower");

            </script>
        }
0
Jerode On

The following JavaScript should do what you need:

<script type='text/javascript'>
    var div = document.createElement("div");
    div.innerHTML = "<!--[if lt IE 9]><i></i><![endif]-->";
    var isIeLessThan9 = (div.getElementsByTagName("i").length == 1);
    if (isIeLessThan9) {
        alert("You're using older version of Internet Explorer");
    }
</script>