00 Votes

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) {
if ($.browser.opera) {
if ($.browser.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.

22 Votes

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:


Otherwise, there is also the possibility to use navigator.userAgent instead:

if (navigator.userAgent.match(/mozilla/i) {
if (navigator.userAgent.match(/webkit/i) {
if (navigator.userAgent.match(/ie/i) {
if (navigator.userAgent.match(/opera/i) {

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

Positive Negative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile


Related Topics

jQuery: Show and hide elements

Tutorial | 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.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.