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
[…] Here is a fast way to solve this problem. Add this line of codes to your jQuery-1.9.js and replace $.browser with jQuery.browser […]
Opera browser choke hog crash so what this plugin/swcript rely does its prevent browser then good but there is no easy way to use it or it does ????
Thank you!
FYI to those dont know, there is a JQuery migrate plugin to handle this issue
http://blog.jquery.com/2013/05/08/jquery-migrate-1-2-1-released/
Nice crutch for old libraries that haven’t rewritten their calls yet; thanks.
Yeah!! It works well (:
Hi, Matteo.
I am having difficulties making it work in Windows 8.
What do you suggest I use?
Thank you.
you’re a rockstar! you really shoud put this up on jQuery plugin page so its easier to find.
Matteo,
I really appreciate your help. I got it to work now.
Thank you so much!
Ed
The way you add the script is wrong.
first download the jquery.mb.browser plugin from the link you find in the article.
than include it as you did for all the other scripts just after the jquery.js as follow:
2
3
<script type="text/javascript" src="inc/jquery.mb.browser.js"></script>
...
obviously the path to jquery.mb.browser must corrispond to the real location of the script in your folder structure.
Bye,
Matteo
Hi, Matteo.
I have used your code before and now the site does not work anymore.
http://www.orsolonracing.com
I apologize in advance but I am confused. I copied the code above but I don’t know what you mean by “include it just after the jquery.js”.
Where exactly should I place the patch?
Thank you for your help.
Hi Michael,
If you include it after all other inclusions it looses its function.
You have to include it just after the jquery.js; that way it reintroduce the $.browser before you load the other scripts. Take in mind that it solves only the $.browser issue not all the others introduced by the new 1.9 jQuery (as for ex. the toggle behavior that is changed or the removal of the bind/unbind replaced by the on/off and so on…).
Bye,
Matteo
Ciao Matteo,
unfortunately it doesn’t work how you described it…
I included the files directly after the other includings and I am also sure that there is no path-error… For now I helped myself by including an iquery-1.8.2.js … But this won’t be good for permanent use, will it?
Ciao Matteo,
The .browser fix works very well however, you’ll notice that the images don’t resize smoothly anymore in jQuery 1.9.0.
During the transition, the images get smaller for a little while and then resize to the correct size of the next image. If you check your demos you’ll see what I mean…
Thanks for any guidance.
Cheers,
Mauricio
Thank you very much !
…
by the way… the lady for whom I made that sample page with iQuery has postponed all… But probably she has just too much to do… http://zoom.zdf.de/ZDF/zdfportal/programdata/befc0476-9f54-36cb-bcb9-43012ec8ac62/20093495?generateCanonicalUrl=true …
Hi Michael,
Yes, this reintroduce the $.browser object solving all the errors you get in jQuery 1.9; If in your code you where catching only the vendor than you can use the 5 lines of code you found in the article; if you where checking the version too than you should download the query.mb.browser plugin (https://github.com/pupunzi/jquery.mb.browser) that returns more browsers specifics based to the User Agent. You should include the script just after the jquery inclusion. That’s all.
Bye,
Matteo
Hi,
I’m going to publish an update of most of the mb.components to fix this issue soon.
Anyway I wrote a plugin that replace the $.browser jquery object to be placed just after the jquery-1.9.js inclusion.
You can find it here:
https://github.com/pupunzi/jquery.mb.browser/archive/master.zip
Hi Matteo,
I really enjoy your script.
Although, as per your post above, I am running into a $.browser error.
Where should I insert the code you have above, in order to bypass the error?
(i.e. does it go on line 1 of jquery.mb.miniPlayer.js?)
Thanks in advance!
hi Matteo,
I have implemented a lot of features with this $.browser method and in fact they don’t work anymore… Is it possible with this code above to make it works again ? – And: could you please tell me where exactly I have to insert the code above ?
Thank you in advance!
I’m perfectly agree with you on using feature detection; this is a fast and dirty workaround to let work all the scripts that uses $.browser for the detection.
I think feature detection is better than using useragent sniffing. Some users may turn off some features or the browser may have a bug so using this technique is not accurate enough.