1

how can I make it so that if the user is not using any version of Internet Explorer to alert them and advise them to use it?

I've tried:

  <html>
   <head>
   <script language="Javascript">
   <![if !IE]>
   alert ("Please use IE")
   <![endif]>
    </script>
    </head>

Thanks

Koala
  • 5,253
  • 4
  • 25
  • 34

2 Answers2

3

If you're using jQuery you can do:

if (!$.browser.msie) {
    alert( "Please Use IE" );
}
dsundy
  • 1,124
  • 6
  • 11
3

You can use:

if (navigator.appName != "Microsoft Internet Explorer")
{
    alert("Please use IE");
}

OR:

if (navigator.userAgent.indexOf("MSIE") == -1)
{
    alert("Please use IE");
}

FYI, you could also use the examples below but Conditional Comments are REMOVED from Internet Explorer 10.

Otherwise you could use:

<!--[if !IE]><!-->
<script type="text/javascript">
   alert("Please use IE");
</script>
<!--<![endif]-->

OR this:

<!--[if IE]><script type="text/javascript">window['isIE'] = true;</script><![endif]-->
<script type="text/javascript">
   if (!window.isIE) alert("Please use IE");
</script>

But still; to get this functionality in IE10; there is a workaround, which is opting into IE 9 behaviour via this meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
Onur Yıldırım
  • 32,327
  • 12
  • 84
  • 98
  • Using the user agent string to identify the browser is seriously flawed. Where there is no other option, conditional comments (per the OP) are likely a much better option. – RobG Feb 13 '13 at 02:44
  • That's for sure. But **conditional comments are removed from IE10**, that's why I did not mention them. (Now, I've added this info). The question does not provide any material to test against feature detection either but still, I'll improve the answer more by focusing on detecting features unique to IE. – Onur Yıldırım Feb 13 '13 at 03:37