javascript 检测 Internet Explorer 并显示消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14544816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:55:08  来源:igfitidea点击:

Detect Internet Explorer and display a message

javascriptjqueryhtml

提问by b2550

I have been looking around and cannot find what I am looking for

我一直环顾四周,找不到我要找的东西

I want to display a warning to IE users that my website does not support IE nor will it ever try to and that you should get a better browser.

我想向 IE 用户显示一个警告,即我的网站不支持 IE,也不会尝试支持,您应该获得更好的浏览器。

How you detect IE is really all I need but it would be nice if someone told me how to trigger a lightbox on the page but I can do that myself if you don't include it

你如何检测 IE 真的是我所需要的,但如果有人告诉我如何在页面上触发灯箱会很好,但如果你不包括它,我可以自己做

Thank's for the help!

谢谢您的帮助!

回答by elclanrs

Conditional HTML comments will work for detecting IE9 or less. From the HTML5 Boilerplate, which I highly suggest you use:

条件 HTML 注释可用于检测 IE9 或更低版本。来自HTML5 Boilerplate,我强烈建议您使用:

<!--[if lt IE 7]>
    <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->

回答by Iswanto San

Try this

试试这个

 if ($.browser.msie) {
    // you are using IE
 }

More detail : jquery.browser

更多细节:jquery.browser

回答by rai.skumar

navigatorobject has all details related to browser and platform details of clients machine.

navigator对象具有与客户端机器的浏览器和平台详细信息相关的所有详细信息。

navigator.userAgentgives browser related details.

navigator.userAgent提供浏览器相关的详细信息。

JS snippet:

JS片段:

<script>
  var x = navigator.userAgent;
  alert(' browser details ' + x);
</script>

Below link talks at length about it in detail :

下面的链接详细讨论了它:

http://www.javascriptkit.com/javatutors/navigator.shtml

http://www.javascriptkit.com/javatutors/navigator.shtml

回答by Yoav

Paste the code after tag:

在标签后粘贴代码:

  <!--[if lt IE 8]>
  <p class="browserupgrade">Vous utilisez un <strong>ancien navigateur</strong>. Mettez votre <a href="http://browsehappy.com" target="_blank">navigateur à jour</a> dès aujourd'hui !</p>
  <![endif]-->

PS: edit the content as you need. I translate it into French for my own use.

PS:根据需要编辑内容。我把它翻译成法语供我自己使用。