How to get the code name and product name of the browser in JavaScript?

Front End TechnologyJavascriptObject Oriented Programming

When a user accesses a web application using JavaScript, the "navigator" object contains details about the browser they are currently using. You may be aware that each browser functions differently when it comes to how it interprets JavaScript. In this case, the navigator object supports in modifying your application to the user's browser preferences.

The browser engine or product name can be viewed in JavaScript by accessing the "navigator.product" attribute of a navigator object. In any browser, "Gecko" is always the value of the Navigator.product property. Only compatibility considerations are used to maintain this characteristic.

Syntax

The JavaScript syntax for the navigator.product property

/regexp/g

Navigator Object navigator.product property

Example 1

In this example let us understand how the navigator navigator.product attribute allows JavaScript to identify the name of the browser. While accessing the "navigator.product" property, newer browsers show "Gecko" as the product name for compatibility concerns.

<!DOCTYPE html> <html> <title>How to get the code name and product name of the browser in JavaScript - TutorialsPoint</title> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div id="result"></div> <script> let productName = navigator.product; document.getElementById("result").innerHTML ="The output of Browser product is: " + productName; </script> </body> </html>

Navigator Object appCodename property

The JavaScript navigator object's "appCodename" field indicates the identity of the browser. In every browser, "Mozilla" is the output of the Navigator.appCodeName field. The only reason this property is preserved is for compatibility. The "browserCodeName" variable in the example below will be used to hold the browser code name returned by the "navigator.appCodeName" property −

Syntax

The JavaScript syntax for the navigator.appCodename property.

navigator.appCodename

Example 2

In this example let us understand how the navigator navigator.appCodename attribute allows JavaScript to identify the browser code name.

<!DOCTYPE html> <html> <title>How to get the code name and product name of the browser in JavaScript - TutorialsPoint</title> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div id="result"></div> <script> let codeName = navigator.appCodeName; document.getElementById("result").innerHTML ="The output of Browser Code Name is: " + codeName; </script> </body> </html>
raja
Updated on 04-Aug-2022 11:18:07

Advertisements