An IE7 Bug That Returns MSIE 6.0 User Agent String

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:
- Most store bough Windows PCs come pre-installed with tons of stupid toolbars and crapware
- IE 7 isn’t much more secure than IE6 was in terms of spyware
- 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)

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: browser, Bug, ie7, JavaScript, jQuery


August 12th, 2008 at 10:12 pm
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 !?!
August 12th, 2008 at 10:55 pm
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;August 13th, 2008 at 5:30 am
[...] 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 [...]
August 27th, 2008 at 7:02 pm
The issue seems to be carried over to IE8 as well. My beta 1 version show both IE8 AND IE6. Gotta love it
August 27th, 2008 at 10:04 pm
FFS. I’m almost certain they’re fucking up on purpose. You just can’t buy that level of incompetence
September 25th, 2008 at 5:50 am
[...] 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 [...]
October 5th, 2008 at 2:12 pm
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?
October 9th, 2008 at 3:57 pm
Are you people completely and uttlerly insane?
Ignore the user agent string (and jQuery.)
Sheesh.
October 9th, 2008 at 4:02 pm
lol. care to elaborate?
October 19th, 2008 at 7:18 am
[...] 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). [...]
October 21st, 2008 at 11:45 pm
jQuery rules.
November 11th, 2008 at 3:35 am
[...] an Ie7 Bug return Ie6 UserAgent String [...]
January 30th, 2009 at 10:07 am
to boot buy cialis pasquil
November 12th, 2009 at 4:51 pm
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.