4

IE8 can go into IE7 mode if it needs to. How does jQuery detect this? Specifically, what is the value of $.browser.version?

5 Answers 5

8

IE8 in IE7 mode will report IE7. BUT you can analyse user-agent and check for "Trident/4.0". If you see this line then you work with IE8

1
  • IE 8 in "IE7 Standards Mode" still reports "8.0" from $.browser.version.
    – bart
    Nov 21, 2012 at 0:46
6

The $.browser obejct is populated using a concept know as Browser-Sniffing. Put simply, this is the processes scanning data out of the user-agent string which is sent by browsers, robots, and anything else that accesses the page.

Due to the susceptiblity of the user agent to faking, this object is deprecated in later versions of jQuery. Object Detection and Feature Detection (see $.support) are now used in preference.

For example, Opera 8.5. used to identify itself as IE: http://www.javascriptkit.com/javatutors/navigator.shtml

$.support:

http://docs.jquery.com/Utilities/jQuery.support

User Agents:

http://en.wikipedia.org/wiki/User_agent

http://www.zytrax.com/tech/web/browser_ids.htm

Object detection:

http://www.quirksmode.org/js/support.html http://developer.apple.com/internet/webcontent/objectdetection.html

Browser Sniffing:

http://en.wikipedia.org/wiki/Browser_sniffing

Feature Detection:

http://docs.jquery.com/Utilities/jQuery.support

2
  • 1
    well, yeah that's nice, but which out of the support properties tells me if IE supports inline-block properly? leadingWhitespace, tbody, objectAll, htmlSerialize, style, hrefNormalized, opacity, cssFloat, scriptEval, noCloneEvent, boxModel
    – nickf
    Aug 19, 2009 at 11:42
  • Not sure if any of them would do that. You could try extending the .support function (see example at: waytoocrowded.com/2009/03/14/jquery-supportminheight), or maybe there's even someone that has extended this already. This is a bit of unknown teritory for me, though. Aug 19, 2009 at 12:21
2

I just tested this out myself (having just downloaded IE8)

When you put IE8 into IE7 compatibility mode with the meta tag like this:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

The value of $.browser.version is still 8.0!

1

JQuery can only see what the browser tells it.

In IE7 mode the browser will report itself as IE7, so that is what JQuery will see.

2
  • 1
    And what the browser tells it can be a lie Aug 19, 2009 at 9:29
  • Well, kind of... When in IE7 mode everything should be as if the browser really was IE7. The browser is reporting the version of the rendering engine, not the actual version of the program.
    – Guffa
    Aug 19, 2009 at 9:33
0

I'm a .NET developer and I always like to use a Sessions.aspx page that I created for this kind'a problems

Fell free to use it, I can share the code as well.

as you can see by this screencast that I just made (14 sec) you get MSIE 8 and MSIE 7 specified in the javascript navigator property, they change when you change compatibility mode as the engine that renders the page is slight different (remember that is not 100% IE7 engine!)

instead of using the jQuery buit in method, just use the normal javascript

IE8 in IE7 mode

4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.30618; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)

IE8 in native mode

4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.30618; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)

code:

var browserVersion = navigator.appVersion.toLowerCase();
if(browserVersion.contains('msie 8') ) {
    // IE 8
}
else if(browserVersion.contains('msie 7') ) {
    // IE 7
}

Screen cast video: http://www.balexandre.com/temp/showFlash.aspx?swf=2009-08-19_1138_ie8ie7.swf&w=952&h=742

1
  • 1
    Wow, that sessions-page is reaaaally outdated
    – Kloar
    May 16, 2013 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.