How to detect browser details?
Table of Contents
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:
VARIABLES | DESCRIPTION |
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
Example
<html> <head> <script type="text/javascript"> function browserDetails(){ alert("appName"+":"+navigator.appName+"\n"+ "appVersion"+":"+navigator.appVersion+"\n"+ "userAgent"+":"+navigator.userAgent); } </script> </head> <body onLoad=browserDetails()> </body> </html>
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. 🙂
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.