【发布时间】:2011-04-22 00:27:39
【问题描述】:
什么是 IE6 等价于 Request.UserAgent.ToLower().Contains("msie")?
如上所述,它明显检测到任何 IE 实例,但我希望仅拉取 IE6 用户,因此我可以显示一条消息,告诉他们该站点将在他们的浏览器中奇怪地呈现。我无法在搜索中找到答案。
【问题讨论】:
标签: c# asp.net internet-explorer-6
什么是 IE6 等价于 Request.UserAgent.ToLower().Contains("msie")?
如上所述,它明显检测到任何 IE 实例,但我希望仅拉取 IE6 用户,因此我可以显示一条消息,告诉他们该站点将在他们的浏览器中奇怪地呈现。我无法在搜索中找到答案。
【问题讨论】:
标签: c# asp.net internet-explorer-6
不要。
要么
改为使用条件 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 字符串是邪恶的。
【讨论】:
如果你真的需要检测浏览器服务器端,使用Request.Browser.Type,它返回“IE6”代表IE6!
【讨论】:
你可以像这样检测 IE6:
if (Request.UserAgent.IndexOf("MSIE 6.0") > -1)
{
// The browser is Microsoft Internet Explorer Version 6.0.
}
但是,您可能不想这样做。最好使用 jQuery(现在由 Microsoft 正式支持)在客户端处理此问题,并使用功能(对象)检测而不是浏览器版本号检测,这将使您的代码更加健壮和面向未来。
【讨论】:
【讨论】: