jQuery 1.9 is out… and $.browser has been removed – a fast workaround

With the new 1.9 jQuery release they removed definitely their $.browser method.

Surely many of you used this thousand of time to catch specific browsers; now it doesn’t work anymore. Here is a fast and short piece of code you can use before deciding how to procede:

jQuery.browser = {};
jQuery.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
jQuery.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
jQuery.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
jQuery.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());

 

This catches the browser vendor but not the browser version, so $.browser.version will fire an exception.

I wrote an extended plugin that replaces the $.browser object including many information retrieved from the user agent;

you can get it from jsfiddle: http://jsfiddle.net/pupunzi/dnJNS/

or download it here: https://github.com/pupunzi/jquery.mb.browser/archive/master.zip