1

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:

Community
  • 1
  • 1
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
  • 1
    Patch your copy of jQuery to use a newer (presumably-fixed) versions' `.browser` object? – Matt Ball Jan 19 '12 at 19:04
  • http://api.jquery.com/jQuery.browser/ The project is stuck at jQuery 1.3.2 until the spec design is finished, but we all know how that goes... How does one "Patch your copy of jQuery"? – Phill Pafford Jan 19 '12 at 19:07
  • 1
    Replace the source code inside of `jquery.js` that generates the `browser` object with the source code from a newer version. – Matt Ball Jan 19 '12 at 19:32

6 Answers6

5

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]-->
LoveAndCoding
  • 7,857
  • 2
  • 31
  • 55
  • @PhillPafford What didn't work about it? Given the code above (and that linked in the quirksmode blog) it should work. Conditional comments are designed very specifically for this, so there isn't really any reason it shouldn't work. – LoveAndCoding Jan 19 '12 at 20:49
  • some of the older Firefox browsers see this as a syntax error when trying this method here: http://stackoverflow.com/a/4226413/93966 – Phill Pafford Jan 19 '12 at 20:56
  • You don't want to do it within a ` – LoveAndCoding Jan 19 '12 at 20:58
  • I even tried moving the IE conditional block outside of the script tags and the same thing – Phill Pafford Jan 19 '12 at 21:02
  • Does it look like the code in [this example](http://jsfiddle.net/U5VeJ/). Because if it does, there is no reason it shouldn't work. I've tested this code in both IE 6, and FF and it correctly alerts the proper value. – LoveAndCoding Jan 19 '12 at 21:09
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/6864/discussion-between-phill-pafford-and-ktash) – Phill Pafford Jan 19 '12 at 21:22
1

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
Emmanuel N
  • 7,350
  • 2
  • 26
  • 36
1

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');
}
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
0

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/

kleinohad
  • 5,800
  • 2
  • 26
  • 34
0

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... }

kennebec
  • 102,654
  • 32
  • 106
  • 127
0

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

Dave Methvin
  • 1,458
  • 10
  • 12