
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to know the browser language and browser platform in JavaScript?
In this article we are going to discuss how to know the browser language and browser platform with the help of examples in JavaScript
To know the various properties of the browser, the JavaScript provides Navigator object. The Navigator object has several properties, which include - connection, credentials, cookies, geolocation, language, platform, etc. We are concerned with Navigator.language and Navigator.platform to know the language and platform of the browser. Let us discuss about them in detail.
Navigator.language
The read-only Navigator.language property returns a string that represents the browser UI language. It returns a string that returns the language version. For example, ‘en’, ‘en-US’, ‘fr’, ‘fr-FR’, etc.
Example 1
The following is an example program to determine the browser language.
<!DOCTYPE HTML> <html> <head> <title>How to know the browser language and browser platform in JavaScript</title> </head> <body style = "text-align:center;"> <h3>To Know the Language of the browser.</h3> <p id="text1"></p> <script type="text/javascript"> document.getElementById("text1").innerHTML = "The Language of the browser is : "+navigator.language; </script> </body> </html>
On executing the above code, the following output is generated.
Example 2
To know the list of preferred languages set by the user, the property navigator.languages is used. They are displayed in the format of most preferred language to least preferred language by the user. The first element of the returned array is navigator.language. The following example demonstrates the navigator.languages property.
<!DOCTYPE HTML> <html> <head> <title>How to know the browser languages and browser platform in JavaScript</title> </head> <body style = "text-align:center;"> <h3>To Know the Languages of the browser.</h3> <p id="text1"></p> <script type="text/javascript"> document.getElementById("text1").innerHTML = "The Language of the browser is : "+navigator.languages; </script> </body> </html>
On executing the above code, the following output is generated.
Navigator.Platform
The read-only Navigator.platform property returns a string that represents the browser platform. Some of the platforms include ‘MacIntel’, ’MacPPC’, ‘Win32’, ’Win16’, ‘Linux x86_64’, and ’Linux i686’.
Example
The following is an example program to determine the navigator platform.
<!DOCTYPE HTML> <html> <head> <title>How to know the browser platform in JavaScript</title> </head> <body style = "text-align:center;"> <h3>To Know the Platform of the browser.</h3> <p id="text1"></p> <script type="text/javascript"> document.getElementById("text1").innerHTML = "The Platform of the browser is : "+navigator.platform; </script> </body> </html>
On executing the above code, the following output is generated.
- Related Articles
- How to get the code name and product name of the browser in JavaScript?
- How to detect if JavaScript is disabled in a browser?
- How to maximize the browser in Selenium?
- How to get the application name and version information of a browser in JavaScript?
- JavaScript Detecting a mobile browser
- How can I make a browser to browser (peer to peer) connection in HTML?
- How to check the current runtime environment is a browser in JavaScript?
- How to redirect if JavaScript is not enabled in a browser?
- How to find the inner height and inner width of a browser window in JavaScript?
- How to share code between Node.js and the browser?
- How to find whether a browser supports JavaScript or not?
- How to disable browser's back button with JavaScript?
- How to stop browser's back button using JavaScript?
- How to check if CSS property is supported in the browser using JavaScript?
- How to perform browser navigations in Selenium?
