Browser compatibility in JavaScript

It is extremely important to understand the differences between different web browsers to handle each one in the best way. Therefore, you must know which browser your website is running from so that it can provide a suitable solution.

It is extremely important to understand the differences between different web browsers to handle each one in the best way. Therefore, you must know which browser your website is running from so that it can provide a suitable solution.

The available navigator object will help identify information about the browser that the website is currently running on.

Properties of Navigator

There are several Navigator-related properties that you can use in your website. Below are the Navigator properties and detailed descriptions of them.

Attribute appCodeName description

This attribute is a string that contains the browser code name, like Netscape for Netscape and Microsoft Internet Explorer for IE.

appVersion

This property is a string that contains the browser version as well as other useful information such as language and its compatibility.

language

This property contains two abbreviations for the language that is used by the browser. Only for Netscape.

mimTypes []

This property is an array containing all MIME types supported by the Client. Only for Netscape.

platform []

This property is a string containing the platform on which the browser is compiled. "Win32" for Windows 32 bit OS.

plugins []

This property is an array containing all plug-ins installed on the client. Only for Netscape.

userAgent []

This property is a string that contains the code name and version of the browser. This value is sent to the Source Server to identify the Client.

Navigator methods

Below is a list of Navigator methods and detailed description of them:

javaEnabled (): This method determines if JavaScript is enabled in the Client. If JavaScript is enabled, this method returns true, otherwise it returns false.

plugings.refresh: This method creates the latest installed plug-in and places plugins with all new plug-in names. Only for Netscape.

preference (name, value): This method allows a script to be marked to receive and set a number of Netscape preferences. If the second parameter is omitted, this method returns the value of the specified priority; otherwise, it sets that value. Only for Netscape.

taintEnabled (): This method returns true if corrupted data (data tainting) is enabled; otherwise false.

Check the browser (Browser Detection)

This is a simple JavaScript code that can be used to find the name of a browser and then send the HTML page that matches that browser to the user.

 Browser Detection Example  type = "text/javascript" >  

Result

 Mozilla based browser 
Browser version info: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36
(KHTML, like Gecko) Chrome / 67.0.3396.99 Safari / 537.36

According to Tutorialspoint

Previous article: Image Map in JavaScript

Next post: What is HTTP

4 ★ | 2 Vote