Javascript 仅在IE浏览器中显示消息的脚本

Javascript 仅在IE浏览器中显示消息的脚本,javascript,Javascript,您知道仅针对internet explorer用户的通知或警告脚本吗 我只需要为此特定浏览器中的用户显示警告 求求你,你能帮我吗?不久前我不得不做这个问题。由于对条件注释的支持被取消,我最终使用了javascript: 我的解决方案最终是这样的: <style> #ie-banner { display: none; /* other styling */ } </style> <div id="ie-banner"

您知道仅针对internet explorer用户的通知或警告脚本吗

我只需要为此特定浏览器中的用户显示警告


求求你,你能帮我吗?

不久前我不得不做这个问题。由于对条件注释的支持被取消,我最终使用了javascript:

我的解决方案最终是这样的:

<style>
    #ie-banner {
        display: none;
        /* other styling */
    }
</style>

<div id="ie-banner">
  <div id="ie-message">
    <h5>INCOMPATIBLE BROWSER</h5>
  </div>
</div>

<script>
    function isOldIE(userAgent) {
      var msie = userAgent.indexOf('MSIE');
      if (msie > 0) {
        // IE 10 or older
        return true;
      }
      // other browser, IE 11, or Edge
      return false;
    }
    if (isOldIE(navigator.userAgent)) {
      var ieWarning = document.getElementById('ie-banner');
      ieWarning.setAttribute('style', 'display: block;');
      // drop off my react app below
      // var root = document.getElementById('root');
      // document.body.removeChild(root);
    }
</script>

#横幅{
显示:无;
/*其他样式*/
}
不兼容浏览器
函数(用户代理){
var msie=userAgent.indexOf('msie');
如果(msie>0){
//10岁或以上
返回true;
}
//其他浏览器,IE 11或Edge
返回false;
}
if(isOldIE(navigator.userAgent)){
var ieWarning=document.getElementById('ie-banner');
ieWarning.setAttribute('style','display:block;');
//在下面下载我的react应用程序
//var root=document.getElementById('root');
//document.body.removeChild(root);
}
请注意,我删除了这样的子对象,并使用较旧的DOM API,因为更多的标准方法根本不适用于IE。。。大惊喜

如果您只关心IE9和down,那么我可能只会使用条件注释。直接从上面的链接:

<html>
  <!--[if IE]>
    This content is ignored in IE10 and other browsers.
    In older versions of IE it renders as part of the page.
  <![endif]-->
</html>

但我想在资源管理器中显示一条消息。没有版本。在我的情况下,我不理解你的代码