Published on: 23 June, 2014

Browser Detection

Posted by andy | 1262 views 1 likes 0 favourites 0 comments
Tumblr Digg Google Plus
There are may kinds of browsers, it can be Chrome, Firefox, Opera or Internet Explorer. Each browser acts and renders HTML differently which force web developers to check what type of a browser, a current user use. By detecting browser client, web developers can load specific type requirements to make sure their website pages are cross platform friendly. One way to check the browser type is by using a build-in keyword navigator. This build-in keyword has the following main properties:
  • appCodeName

    This is the code name of the browser for ex: Mozilla

  • appName

    This is the name of the browser for ex: Microsoft Internet Explorer

  • userAgent

    This will return the user agent header information.

The following javascript will help you to detect the browser type.
function checkBrowser(){
   if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
     return "Firefox";
   }else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
     return "IE";
   }else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
     return "Opera";
   }else{
     // you can add more condition in here.
     return "Not Specified";
   } 
}
Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Related Articles
Published on: 20 June, 2016
Google Analytics is one of the best free analytics site tracker. It gives you an idea the statistic of your visitors like the country they come from, the URL or keyword they search to go to your site or even the demographic or ages of your visitors. If you are a developer, you definitely do not want to track any data when you are in development phase. In this tutorial, you will learn how to disable google analytics for local development by using a javascript code if condition.
Published on: 13 May, 2016
To convert a number value into money format in Javascript can be done easily using Javascript. Firstly you will need to use the built in toFixed function that will return a number value into two decimal point and then using a regular expression to reformat the value.