0

Possible Duplicate:
What’s the replacement for $.browser

I rely on jQuery's deprecated $.browser functionality to apply quirk fixes for certain browsers. Example:

if ($.browser.msie && $.browser.version < 9) {

This functionality was removed in jQuery 1.9 so I'm looking for an alternative. jQuery suggests using Modernizr for feature detection, but that plugin doesn't appear to cover the functionality I need. What's the (un)official replacement for this functionality?

Community
  • 1
  • 1
Pieter
  • 31,619
  • 76
  • 167
  • 242

2 Answers2

3

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9

From jQuery API documentation:

Rather than using $.browser to detect the current user agent and alter the page presentation based on which browser is running, it is a good practice to use feature detection. To make this process simpler, jQuery performs many such tests and sets properties of the jQuery.support object.

For a more advanced feature detection you shoul yse Modernizr as @Pointy suggested.

Corneliu
  • 2,932
  • 1
  • 19
  • 22
  • Gotcha, I'll remember that from now on. But I'm updating old code right now and rewriting that for feature detection would take more time. – Pieter Jan 31 '13 at 16:11
2

If you import Modernizr, you can test for an IE version with something like this:

if ($('body').is('.lt-ie9 *')) {
  // IE8, 7, 6 ...
}

edit — oops I fixed it; $(document) doesn't work and I can't remember why at the moment.

Modernizr also has lots of more specific feature detection abilities, and it's configurable so you can get only the detection you need. It can't detect everything; things like layout bugs are hard to detect automatically.

Pointy
  • 405,095
  • 59
  • 585
  • 614