Web browsers are the basic software application used by millions of users daily to surf the internet. It interprets web pages into human readable form so that user can easily complete their needful transactions. However in recent times browser making companies has set high standards to meet user needs and provides extra security to surf the web.
But such decent up-gradation gives few headaches to developers who fights with the code for compatibility issues among various popular browsers. Browser compatibility for web applications is a big challenge for developers. So let’s understand how to detect browser features before creating an application or just for individual research with JavaScript.
Note: JavaScript is a client side scripting language used to place validation on web forms, develop web and mobile applications and communicate asynchronously. Its syntax inherited from C language and also copies naming convention from JAVA.
Detect browser brand with JavaScript
We can detect browser brand with the help of JavaScript. navigator.appName property returns a string that the browser manufacturer’s mention while developing browsers. Mozilla Firefox, Chrome & Safari returns “Netscape” while on the other side Microsoft Internet Explorer returns “Microsoft Internet Explorer“.
JavaScript program:
<script>
var x = navigator.appName; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detect browser code with JavaScript
navigator.appCodeName property returns code name of the browser. But mostly advance browsers returns “Mozilla”.
JavaScript program:
<script>
var x = navigator.appCodeName; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detect Browser Version
To detect browser version we can use navigator.appVersion property. It returns complete information about the browser and operating system.
JavaScript program:
<script>
var x = navigator.appVersion; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detect Cookies in browser
To check for the cookie feature in browser we can use navigator.cookieEnabled property of JavaScript. It returns Boolean value such as “True” on cookies enabled in browser and “False” on cookies disabled in browser.
JavaScript program:
<script>
var x = navigator.cookieEnabled; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detecting browser header
navigator.userAgent property of JavaScript returns user agent header sent by browser to the server. It contains information about the name, version and platform of the browser.
JavaScript program:
<script>
var x = navigator.userAgent; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Using navigator.platform property
This property returns for which platform the browser is compiled. For example if you use Windows platform then it will return “Win32“.
JavaScript program:
<script>
var x = navigator.platform; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detect browser language
We can detect browser language by navigator.language property of JavaScript. It returns browser language such as “en-US“.
JavaScript program:
<script>
var x = navigator.language; // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Detect Java in browser
We can also check for Java in our browsers with navigator.javaEnabled() property of JavaScript. As Java plugin is required to run java enabled components in browser so we must install java plugin in our browser to run applications properly.
JavaScript program:
<script>
var x = navigator.javaEnabled(); // Declaring variable and assigning property to variable.
document.writeln(x); // Printing value within variable.
</script>
Note: Browser features changes from time to time so readers are advised to stay updated with the latest browser features. Always write your code before understanding browser features for any compatibility issues.
Uploaded by: Author