1

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.

7
  • I think this is one of the cases where checking the user agent string (= detecting based on name and not features) may be the right way to go. Commented Oct 17, 2012 at 22:33
  • Look at this question: [stackoverflow.com/questions/3165489/… [1]: stackoverflow.com/questions/3165489/… Commented Oct 17, 2012 at 22:34
  • @weexpectedTHIS ah, yeah, saw both before I posted. Both use .browser which is deprecated. Commented Oct 17, 2012 at 22:35
  • 2
    .browser is 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. Commented Oct 17, 2012 at 23:10
  • What is the hack code you are using for IE7? Maybe if you showed that, we could give you a better solution. Commented Oct 17, 2012 at 23:27

3 Answers 3

3

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
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

I have seen this code before, but didn't realize what it was doing. Is there any caveat to doing browser detection like this?
I couldn't say for sure, but H5BP is created (and audited) by people a lot smarter than me, so that's a good indication it's ok. More details here: github.com/h5bp/html5-boilerplate/blob/v4.0.0/doc/html.md
0

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

Kinda the same problem with IE 8. The jQuery .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.
@typoknig - I'm talking about doing your own feature detection code, not relying on undocumented things in jQuery so I'm not talking about using jQuery.support at all. It's easy to detect most features yourself.
0

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

Yeah, I know using .browser is bad, that is why I posted the question :)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.