Home » Web Development » Should you be using that Browser ?

Should you be using that Browser ?

Internet Explorer Mobile Logo

Image via Wikipedia

While my favorite browser is always Mozilla Firefox, when developing Web Applications, web developers often resort to the classic problem of detecting Web Browser as to which browser was being run on client side.  Our most humble browser, which is regarded as most secure and fast, Internet Explorer behaves like a small child who will not behave no matter what you do. Internet Explorer is one big sickening (yeah I am still thinking a better word to describe all version of IE, 6, 7, 8, and now 9) browser with which all the viruses, Trojans are installed on the system and Web developers go through hell developing applications.

The basic reasons to detect Browsers could be

  • to display a nice message not to use the current browser, that is, Internet Explorer
  • to re-direct the browser to another page, either informing the user or transparently to another page which is more compatible to the current browser.

I decided, for the time being, to display the alert box informing the user that we run on Firefox. Please switch to Firefox.

Here goes the code.

function checkBrowser()
{
 if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access our application using Google Chrome, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");

 }
 else if (navigator.userAgent.toLowerCase().indexOf('sea') > -1)
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access our application using Sea Monkey, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");
 }

 else if (navigator.appName == "Microsoft Internet Explorer")
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access TPS tracker using Microsoft Internet Explorer, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");
 }
 else if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
 {
 // Yo... You are using the right Browser.
 }
 else if (navigator.userAgent.toLowerCase().indexOf('k-meleon') > -1)
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access our application using K Meleon, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");}
 else if (navigator.userAgent.toLowerCase().indexOf('midori') > -1)
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access our application using Midori, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");}
 else if ( navigator.appName== "Opera")
 {
 alert ("Hi, \n\nWhile we appreciate, that you want to access our application using Opera, we would like you to inform you, that we sail smooth on Mozilla Firefox 3 and above. \n\nWe request you to please switch your browser to Mozilla Firefox. \n\nIt can be downloaded from http://getfirefox.com");
 }
}

Please keep in mind, that I have developed the code which will detect the name of browser only, not their versions. To detect the versions and other information, follow this link.

http://lmgtfy.com/?q=how+to+detect+browser+versions

Advertisements

One thought on “Should you be using that Browser ?

  1. Pingback: Tweets that mention Should you be using that Browser ? « سلمان کے خیا لآ ت -- Topsy.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s