It can be detected in both cases by examining the User-Agent string. Note that browsers can spoof their UA string, but now this is less common than in the past. See this article on MSDN for older UA strings.
Note that IE8 sends another UA string in compatibility mode and standard mode (see this and this - both are IE8, although the first one says MSIE 7.0).
See this for a long list of UA strings - note that you should look for a pattern, not an exact match, as the installed software will change the UA string.
In IE9 there is a new line of the line - see IEBlog for more details .
To summarize (and borrow from @EricLaw's comment ):
- no Trident in UA string - check string
MSIE [0-9].0for version - Trident / 4.0 - IE 8, Version B
MSIEDoesn't Matter - Trident / 5.0 - IE 9
source
share