最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - If other than IE show alert - HTMLJS - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question asked Feb 13, 2013 at 2:02 KoalaKoala 5,5434 gold badges26 silver badges34 bronze badges 3
  • 13 Wait.. you want your users to use IE? – Piccolo Commented Feb 13, 2013 at 2:04
  • 1 Perhaps the OP works for Microsoft... – Lee Taylor Commented Feb 13, 2013 at 2:05
  • 1 stackoverflow./questions/4169160/… – Matt Commented Feb 13, 2013 at 2:05
Add a ment  | 

2 Answers 2

Reset to default 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">

If you're using jQuery you can do:

if (!$.browser.msie) {
    alert( "Please Use IE" );
}
发布评论

评论列表(0)

  1. 暂无评论