An IE7 Bug That Returns MSIE 6.0 User Agent String

July 23rd, 2008

Internet Explorer 7 User Agent Bug (MSIE 6.0)

IE7, don’t you just love it? What they gave us with one had in terms of CSS actually sort of working they took away with some of the stupidest niggly little bugs ever. Here’s another potentially large one i’m stumbled right into recently.

If your user agent string is more than 260 characters in length then your user agent string suddenly and almost magically becomes “Mozilla/4.0 (compatible; MSIE 6.0)”

Not what you’d expect to happen. Now, I know what your thinking. Why on god’s earth would your user agent string BE that long. The answer is simple. Toolbars and Spyware.

Toolbars and Spyware

The cool thing about Windows is that toolbars, spyware and crapware in general can and do add pointless shit to your Internet Explorer user agent string via the registry. Sounds good doesn’t it. Now consider the following:

  1. Most store bough Windows PCs come pre-installed with tons of stupid toolbars and crapware
  2. IE 7 isn’t much more secure than IE6 was in terms of spyware
  3. Home users do not know or care about viruses and spyware

With me?

Try it yourself

You can easily trigger this bug yourself by editing the registry. Fire up regedit and navigate to HKLM/Software/Microsoft/Windows/CurrentVersion/Internet Settings/5./0User Agent/Post Platform. Create a new string key and fill up full of crap (enough to pass the 260 character threshold)

regedit

Next, close all instances of IE. Fire UP IE again and type the following into the address bar:

javascript:alert(navigator.userAgent)

Hit enter and IE7 should now tell you that it’s IE6. Awesome!

I firmly believe that this is one of the reasons behind problems such as the thickbox positioning bug that many people experience with IE7.

The workaround?

This is of course just another argument against relying on the user agent string to determine browser version. It really shouldn’t be done this way, yet it’s the method built into many JavaScript libraries including jQuery with it’s unreliable $.browser.version property.

If you really need to know if a browser is IE6 or IE7 then use something more solid like object detection. Simply testing for something like the following would be a better option than extracting unreliable data from the user agent string

A possible patch below redefines the browser version as “7.0″ only if the browser has already been identified as IE6 and the the presence of the XMLHttpRequest object suggests otherwise.

if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 && this.XMLHttpRequest) {
jQuery.browser.version = "7.0"
}

I’m thinking though that maybe this might not be bulletproof. If IE8 presents the same or similar “Hi i’m IE6!” behaviour then the above patch could incorrectly identify IE8 as IE7. This might not be as serious as IE7 vs. IE6 but it’s still an issue.

I just wish that Microsoft would put a bit more effort into writing good software. It’s not like they don’t have the resources.

Posted in Web | Tagged with: , , , ,

14 Responses

  1. Eric Martin

    I’ve been messing around with this issue and have been looking for a “fix”.

    I think your workaround might do the trick…I tried the registry hack in IE8 beta and believe it or not, navigator.userAgent actually reported MISE 8.0 !?!

  2. Eric Martin

    this.XMLHttpRequest didn’t seem to work for me, but window["XMLHttpRequest"] did:

    $.browser.version = $.browser.msie && parseInt($.browser.version) == 6 && window["XMLHttpRequest"] ? “7.0″ : $.browser.version;

  3. Eric Martin » jQuery & Browser Issues

    [...] situations, jQuery’s $.browser.version will report IE 7 as version 6. Jamie Thompson noted one possible situation on his blog, but typically the issue is caused due to the fact that some copies of IE 7 included [...]

  4. James

    The issue seems to be carried over to IE8 as well. My beta 1 version show both IE8 AND IE6. Gotta love it

  5. Jamie Thompson

    FFS. I’m almost certain they’re fucking up on purpose. You just can’t buy that level of incompetence

  6. IE Version Reporting in jQuery » Daniel Bergey

    [...] might want to pretend it was IE 6 for compatibility with older pages. There’s also apparently a situation wherein an extra-long Windows registry entry will overwhelm IE 7 to the point where it falls back [...]

  7. Ian Ambrose

    Hi - I’m having a problem with IE7 is being recognised as IE6 by some site with double agent strings being returned (one of which is incomplete):

    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Sky Broadband;
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )

    Any ideas how I can correct it to show only IE7?

  8. David Mark

    Are you people completely and uttlerly insane?

    Ignore the user agent string (and jQuery.)

    Sheesh.

  9. Jamie Thompson

    lol. care to elaborate?

  10. zachleat.com » jQuery Bug: IE reports incorrect $.browser.version

    [...] can monitor the jQuery bug in the bug tracker, or see the original research performed by Jamie Thompson. Take note that the fix represented on his page isn’t future proof (and will not work in IE8). [...]

  11. Adam Sentz

    jQuery rules.

  12. Interesting Finds: 2008.11.08~2008.11.11 - gOODiDEA.NET

    [...] an Ie7 Bug return Ie6 UserAgent String [...]

  13. EffoneEthinia

    to boot buy cialis pasquil

  14. webguy

    Add the bgiframe plugin for jQuery to the mix and your site will completely freeze in IE7 if it’s detected as IE6 due to an infinite loop in the detection of offset width.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.