2010-10-06 82 views

回答

2

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

+0

感谢大家的帮助和建议,最终我只能选择一个正确的答案,而这个答案最直接的答案是正确的 – korben 2010-10-06 20:51:08

0

这有帮助吗?

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

MSDN help doc表明MSIE 6.0为IE6用户代理字符串内。

4

不要。

或者

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

输出这个直接到Web页面:

<!-- [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> 

它普遍认为,解析用户代理字符串是邪恶的。

+0

另一个更突出的更新JavaScript:http://code.google.com/p/sevenup/ – 2010-10-06 19:34:31

2

您可以检测IE6就像这样:

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

然而,你可能不希望这样做。更好的方法是在客户端使用jQuery(现在由Microsoft正式支持)处理此问题,并使用功能(对象)检测代替浏览器版本号检测,这将使您的代码更健壮,并且将来可以证明。

+0

天哪,这看起来奇怪的类似于MSDN文章的实现! – 2010-10-06 19:18:59

+0

@ p.campbell MSDN是我的朋友。 ;-) – GeneQ 2010-10-06 19:21:12

相关问题