The lowest browser my application supports is IE 7. I have some code that works fine in IE 8, but needs to be avoided in IE 7. There are a ton of questions/answers on here that indicate how to detect IE 7 with .browser but none that indicate how to detect only IE 7 with .support. The jQuery page detailing .support does not make it clear which supported features are present in which browsers, so not getting much help there.
3 Answers
The reason they deprecated .browser is to try to encourage us to test for features instead of browsers.
However.. if you still need to...
Have you considered using H5BP's conditional <html> trick and then just testing for that? Header:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
Then in jQuery,
$(function() {
if( !$('html').hasClass('lt-ie8') ) {
// Do stuff
}
});
2 Comments
It is nearly always better to identify the features you are targeting in IE8 and use "feature detection" to see if they are available (by testing the feture's functionality) and if they are not available, then use alternate code (for IE7 or any other browser without that feature).
If you offer more specifics on the functionality that doesn't work in IE7, we could help you solve this problem with feature detection, not browser version detection.
2 Comments
.support page does not do a good job of indicating what features are available in what browsers so I don't know how to narrow down that a browser is IE 8 using .support.Did you look at the API for $.browser?
http://api.jquery.com/jQuery.browser/#jQuery-browser-version2
But there is a reason why it is deprecated, it is a bad thing to do. You should sniff using feature detection.
1 Comment
.browser is bad, that is why I posted the question :)
.browserwhich is deprecated..browseris deprecated for the exact same reason that you're trying to use it for. The new standard is to use proper feature detection instead of sniffing userAgent strings or blocking solely older versions of IE. It is very possible that someone may have Firefox 2 installed or some hipster browser that has absolutely no HTML5 support, that's why simply testing for older versions of IE is deprecated.