How to detection browser using Javascript

Posted By  ansari.najmul@gmail.com On 14 Aug 2010 01:08:53
emailbookmarkadd commentsprint
No of Views:1712
Bookmarked:0 times
Votes:0 times

Introduction

Before explaining the article, I would like to thank all readers who read my article and voted for it. Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions. Now I won't waste your time and come back to the topic. I have written this article on ‘Browser Detection’. Sometimes it can be very useful to detect the visitor's browser, and then serve up the appropriate information.

So, sometimes it can be very useful to detect the visitor's browser, and then serve up the appropriate information.The best way to do this is to make your web pages smart enough to look one way to some browsers and another way to other browsers.

JavaScript includes an object called the Navigator object, that can be used for this purpose.The Navigator object contains information about the visitor's browser name, version, and more.
The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:

  • appName - holds the name of the browser
  • appVersion - holds, among other things, the version of the browser

The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number.

To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.

 

IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft starts the appVersion string with the number 4.0. In IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.


The example below displays a different alert, depending on the visitor's browser.

i hope this is help to you all.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
By:NarasimhaDate Of Posted:10/27/2010 8:46:43 AM
Narasimha
Hi, the article is good but with limited information.I have noticed two mistakes and explained below. 1) * appName - holds the name of the browser * appVersion - holds, among other things, the version of the browser The variable "browser" in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer". in the above text, i think the "browser" needs to be replaced with "appName". 2) Also, i think you can remove the text "Sometimes it can be very useful to detect the visitor's browser, and then serve up the appropriate information." from the first paragraph, as it was written in 2nd paragraph. can you please check this and update the article. Thanks, Narasimha
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top