jQuery: Detect Browser (Browser Switch)
Info by Progger99 | 2012-07-21 at 22:36
In jQuery, it is quite easy to detect which browser is currently browsing the page. With this, you can easily and quickly program a browser switch.
Here is a first simple example:
if ($.browser.mozilla) { alert('Mozilla Firefox'); } if ($.browser.chrome) { alert('Chrome'); } if ($.browser.opera) { alert('Opera'); } if ($.browser.safari) { alert('Safari'); } if ($.browser.msie) { alert('Microsoft Internet Explorer'); }
Also the version of the browser can be easily detected:
if ($.browser.msie && $.browser.version <= 6) { alert('You are using Internet Explorer 6 or a lesser version.'); } else { alert('You are using a proper browser.'); }
So, you can easily notice with which browser and which version you are dealing at the moment and you can deliver fitting code for the appropriate browser.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
jQuery: Assign Action to Keyboard Keys (Keyboard Event)
Tip | 0 Comments
JavaScript: Set and read Input Value without jQuery using pure JavaScript
Question | 1 Answer
JavaScript: Catch Submit of Form
Tutorial | 0 Comments
jQuery: Does an Element exist?
Tip | 1 Comment
jQuery: Show and hide elements
Tutorial | 0 Comments
Simple CSS Browser Switch for Internet Explorer without Hack
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Unfortunately, today, my described jQuery function $.browser is marked as depreciated and no longer available/removed since jQuery 1.9 so that you can not use this function by simply using the newest version of jQuery. I would like to give you a workaround for this issue with this post.
First suggestion: If you really want to use an easy way of detecting browser using jQuery, the simplest possibility is to use the last working version of jQuery before 1.9 which is still supporting the function:
http://code.jquery.com/jquery-1.8.3.min.js
Otherwise, there is also the possibility to use navigator.userAgent instead:
Another way is using the plugin jQuery Migrate, which gives you backwards-compatibility in new jQuery versions. This plugin is providing all of the functions removed today.
2013-05-10 at 23:56