jQuery 1.8 – $.browser has been deprecated
With the new jQuery release 1.8 they are going to remove the $.browser method (definitely removed on the 1.9 v.):
$.browser: Ever since jQuery 1.4, we’ve been evangelizing that browser detection via the user agent string is a bad idea. Yet we’ve been an enabler of bad practice by continuing to offer $.browser. As of jQuery 1.9 we’ll remove it entirely and you’ll need to use the 1.9 compat plugin. If your code isn’t weaned off browser detection yet, check out Modernizr for a very thorough set of feature detections you can use instead. And of course, you’re welcome to read the tea leaves in the navigator.userAgent string directly, there’s nothing stopping you but your conscience.
As many of my components are using this method for browser detection I’ll make a global refactor for all of them. Anyway I found out that $.browser.webkit doesn’t work anymore for Chrome with jQuery 1.8.
You can fix it either pointing to the previous version of jQuery (1.7) or adding this code before the components javascript files are loaded:
/*Browser detection patch*/ 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
I know this is not very clean and I’m looking for something better, but it’s the faster way to solve it :-).
[…] early has year the $.browser function was deprecated. Since then some bugs have been filed against it but because it is deprecated, the jQuery team has […]
[…] JQUERY 1.8 – $.BROWSER HAS BEEN DEPRECATED […]
This is a slight annoyance. I mean, I can understand getting rid of that and encouraging feature detection, but that doesn’t help me when I’m trying to use certain stylesheets for specific browsers.
Wow. Just… excellent. As a representative for a major corporation looking to remove any deprecated jQuery references, but still requiring a jQuery.browser plug-in, I have to say that this was a HUGE help. Thanks so much for your contribution.
[…] JQUERY 1.8 – $.BROWSER HAS BEEN DEPRECATED […]
`$.browser` is completely removed from jQuery 1.8 (=== undefined), so I had to change the code to initialize the $.browser before assigning the specific browser booleans to it.
Thank you 🙂