some none IE browsers are showing true for IE6 Bro

2019-07-26 08:04发布

问题:

So I'm running jQuery 1.3.2 (yep it's old and right now I can't upgrade).

Problem is I'm trying to drop IE6 support for our internal site and upgrade the browser. I have this check

if($.browser.msie && $.browser.version=="6.0") {
    // do something...
}

But during testing (some) Firefox users are seeing the do something condition and should'nt be. Here are some of the User Agents that I think might be causing the issue.

  • UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23
  • UserAgent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.25) Gecko/20111212 Firefox/3.6.25
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12

Is there more IE6 validation I need?

Note: The end user has no add-ons installed. I was thinking something like IE-Tabs could cause the issue but that's not the case

UPDATE:

All of the responses below lead me to this, still testing but it looks good. Any thoughs on how to improve it?

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}

Related questions:

  • jQuery detect IE6 using jQuery.support NOT jQuery.browser
  • Detecting IE6 using jQuery.support

回答1:

Don't use browser detection. Feature detection is much nicer. And if you want to display a message or something to only IE 6 users, I would recommend using conditional comments instead.

<!--[if IE 6]>
    <script type="text/javascript">
        // do something...
    </script>
<![endif]-->


回答2:

From jQuery Documentation

The $.browser property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery....

It is always best to avoid browser-specific code entirely where possible. The $.support property is available for detection of support for particular features rather than relying on $.browser.

Altenatively you can use:

  1. Write custome browser detector using navigator object
  2. IE conditional statements, something like this


回答3:

Thanks all to helped me find what I was looking for, maybe this might help others

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}


回答4:

You can use this: <!--[If IE 6]> Your code here <![endif]--> will target IE6 only. http://www.unintentionallyblank.co.uk/2006/09/19/if-internet-explorer-then-do-something-else-a-how-to/



回答5:

if you want a line of script to find IE6 and below and you can't use conditional comments:

if('\v'==='v' && !window.XMLHttpRequest) { // do something... }



回答6:

What is the thing you are trying to do that requires knowing if the browser is IE6? Let's eliminate that.