【问题标题】:What is the IE6 equivalent to Request.UserAgent.ToLower().Contains("msie")?Request.UserAgent.ToLower().Contains("msie") 的 IE6 等价物是什么?
【发布时间】:2011-04-22 00:27:39
【问题描述】:

什么是 IE6 等价于 Request.UserAgent.ToLower().Contains("msie")?

如上所述,它明显检测到任何 IE 实例,但我希望仅拉取 IE6 用户,因此我可以显示一条消息,告诉他们该站点将在他们的浏览器中奇怪地呈现。我无法在搜索中找到答案。

【问题讨论】:

    标签: c# asp.net internet-explorer-6


    【解决方案1】:

    不要。

    要么

    改为使用条件 cmets。这是定位 IE 版本的正确方法。

    直接输出到网页:

    <!-- [if lte IE 6]
    <div id="ie6div">This page may not behave correctly in your browser. I suggest you <a href="http://browserupdate.org">update</a> your browser.</div>
    -->
    

    或者

    使用浏览器更新javascript:

    <script type="text/javascript"> 
    var $buoop = {} 
    $buoop.ol = window.onload; 
    window.onload=function(){ 
     if ($buoop.ol) $buoop.ol(); 
     var e = document.createElement("script"); 
     e.setAttribute("type", "text/javascript"); 
     e.setAttribute("src", "http://browser-update.org/update.js"); 
     document.body.appendChild(e); 
    } 
    </script> 
    

    人们普遍认为,解析 User-Agent 字符串是邪恶的。

    【讨论】:

      【解决方案2】:

      如果你真的需要检测浏览器服务器端,使用Request.Browser.Type,它返回“IE6”代表IE6!

      【讨论】:

      • 感谢大家的帮助和建议,最终我只能选择一个正确的答案,而这个最直接的回答正确
      【解决方案3】:

      你可以像这样检测 IE6:

      if (Request.UserAgent.IndexOf("MSIE 6.0") > -1) 
      {
         // The browser is Microsoft Internet Explorer Version 6.0.
      }
      

      但是,您可能不想这样做。最好使用 jQuery(现在由 Microsoft 正式支持)在客户端处理此问题,并使用功能(对象)检测而不是浏览器版本号检测,这将使您的代码更加健壮和面向未来。

      【讨论】:

      • 天哪,看起来与 MSDN 文章的实现非常相似!
      • @p.campbell MSDN 是我的朋友。 ;-)
      【解决方案4】:

      这有帮助吗?

      Request.UserAgent.ToLower().Contains("msie 6.0");
      

      这个MSDN help doc 表明MSIE 6.0 在IE6 的用户代理字符串中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-08
        • 2014-06-12
        • 1970-01-01
        • 2022-11-28
        • 2017-12-20
        • 1970-01-01
        • 2018-07-10
        • 2023-04-10
        相关资源
        最近更新 更多