How to detect browser details?

How to detect browser details?

Each and every browsers(IE, Mozilla, Chrome, Safari etc….) having own properties and own setup. Then while creating website we need to check out cross browser. Some of the functionality in the website we have to write logic according the browser specific. Then how to detect browser details? Let’s us understand it in this post.

The JavaScript that will detect the browser makes use of the navigator object. This object holds these interesting variables:

navigator Variables

navigator.appCodeName The code name of the browser (e.g. Mozilla)
navigator.appName The name of the browser (e.g. Netscape or Microsoft Internet Explorer)
navigator.appVersion The browser version (e.g. 3.0 or 4.0)
navigator.userAgent The header information for the browser. (e.g. Mozilla/4.0)
navigator.platform The users operating system (e.g. WIN32)

Browser Detection Script

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after “Opera” or after “Version”
if ((verOffset=nAgt.indexOf(“Opera”))!=-1) {
browserName = “O

How To Test

  • Create one HTML file.
  • In the HTML header section enable JavaScript using like <script type=”text/javascript”></sript>
  • Create one function inside JavaScript block
  • Call that function from HTML boady


<script type="text/javascript">
function browserDetails(){
<body onLoad=browserDetails()>

Copy and paste it in the file and save it as .html extension and open in the browser and see the output.


If you are satisfied or want to give any suggestion, please comment us in the below. 🙂

The Author


Hello! I am Narayanaswamy founder and admin of I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.