开发者

What is the IE6 equivalent to Request.UserAgent.ToLower().Contains("msie")?

开发者 https://www.devze.com 2023-01-18 20:18 出处:网络
What is the IE6 equivalent to Request.UserAgent.ToLower().Contains(\"msie\")? As开发者_Go百科 above it detects any instance of IE obviously, but I\'m looking to only pull IE6 users so I can display a

What is the IE6 equivalent to Request.UserAgent.ToLower().Contains("msie")?

As开发者_Go百科 above it detects any instance of IE obviously, but I'm looking to only pull IE6 users so I can display a message telling them the site will render oddly in their browsers. I haven't been able to find the answer in my searches.


Don't.

Either

Use conditional comments instead. That's the proper way to target versions of IE.

Output this directly to the web page:

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

Or

Use the browser update 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> 

It's generally agreed that parsing the User-Agent string is evil.


If you really need to detect the browser server-side, use Request.Browser.Type, it returns "IE6" for IE6!


You can detect IE6 like so:

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

However, you probably don't want to do that. Better to handle this on the client side using jQuery (now supported officially by Microsoft) and use feature (object) detection instead of browser version number detection which will make your code more robust and future proof.


Does this help?

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

This MSDN help doc shows that MSIE 6.0 is within the user agent string for IE6.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号