0

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

kez
  • 2,273
  • 9
  • 64
  • 123

2 Answers2

3

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>
        }
Manoz
  • 6,507
  • 13
  • 68
  • 114
  • I'm getting following error when I put that `'string' does not contain a definition for 'ConvertTo' and no extension method 'ConvertTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)` – kez Jun 24 '15 at 09:09
  • @kez, Check now if it helps you – Manoz Jun 24 '15 at 09:12
  • when put it its compiled smoothly, but when i deploy it in ie edge getting following error `System.FormatException: Input string was not in a correct format` – kez Jun 24 '15 at 09:25
  • @kez, Check now if it helps – Manoz Jun 24 '15 at 09:33
0

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>
Jerode
  • 490
  • 4
  • 15