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

My new addiction


Online Flash Games, epecially, when they are linked to my favourite browser (opera). I was just surfing around, and came across this awesome opera widget( http://widgets.opera.com/widget/11271/) and then I went further to it’s parent website (http://www.sarkscape.com/games/). I am hooked to this game for like more than a week, and still can’t get enough of it. My highest score is travelling 70 Meters. What’s yours.?