How to know the browser language and browser platform in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Javascript has provided navigator object to know any details regarding the browser. It has provided navigator.platform and navigator.language to get the details regarding the platform and language of the browser respectively. Let's discuss each of them individually.

Browser-platform

syntax

platform = navigator.platform;

Example

To get the platform on which browser works, the navigator object has provided navigator.platform. some of the platforms are  "MacIntel", "Win32", "WebTV OS".

 Live Demo

<html>
<body>
<script>
   document.write("browser platform is " + navigator.platform);
</script>
</body>
</html>

Output

browser platform is Win32


Browser-language

syntax

language = navigator.language;

Example

To get the language of the browser, the navigator object has provided navigator.language method. We can change the language depending on our convenience. Some of the most commonly used languages are en-GB and en-US

Live Demo

<html>
<body>
<p id="language"></p>
<script>
   document.getElementById("language").innerHTML =
   "browser language is " + navigator.language;
</script>
</body>
</html>

Output

"browser language is en-US
raja
Published on 25-Jul-2019 12:10:05
Advertisements