Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to get the application name and version information of a browser in JavaScript?
JavaScript provides a navigator object that contains information about the browser. To get the application name and version information, the navigator object provides navigator.appName and navigator.appVersion properties respectively.
Application Name of the Browser
The navigator.appName property returns the application name of the browser. However, due to historical reasons, most modern browsers (Chrome, Firefox, Safari, Edge) return "Netscape" regardless of their actual name.
Example
<html>
<body>
<script>
document.write("Application Name: " + navigator.appName);
</script>
</body>
</html>
Output
Application Name: Netscape
Browser Version Information
The navigator.appVersion property provides detailed version information about the browser, including the operating system, browser engine, and version numbers.
Example
<html>
<body>
<script>
document.write("Version Info: " + navigator.appVersion);
</script>
</body>
</html>
Output
Version Info: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Better Alternative: Using navigator.userAgent
For more reliable browser detection, consider using navigator.userAgent which provides the complete user agent string:
<html>
<body>
<script>
document.write("User Agent: " + navigator.userAgent);
document.write("<br>App Name: " + navigator.appName);
document.write("<br>App Version: " + navigator.appVersion);
</script>
</body>
</html>
Key Points
- navigator.appName returns "Netscape" for most modern browsers
- navigator.appVersion provides detailed version and system information
- These properties are legacy and may not accurately represent the actual browser
- Use navigator.userAgent for more comprehensive browser information
Conclusion
While navigator.appName and navigator.appVersion provide basic browser information, they have limitations due to historical web compatibility reasons. For modern applications, consider using navigator.userAgent or feature detection instead.
