The language
property returns the language version of the browser.
language |
Yes | No | Yes | Yes | Yes |
navigator.language
Type | Description |
---|---|
String | The language version of the browser. |
The following code shows how to get the language of your browser.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w w w. j a v a 2s . c o m-->
<p id="demo"></p>
<script>
function myFunction() {
var x = "Language of the browser: " + navigator.language;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
A demonstration of all navigator properties.
<!DOCTYPE html>
<html>
<body>
<!-- w ww.ja v a 2 s . c om-->
<div id="demo"></div>
<script>
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Browser Language: " + navigator.language + "</p>";
txt+= "<p>Browser Online: " + navigator.onLine + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
The code above is rendered as follows:
A demonstration of browserLanguage for IE.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w w .jav a2 s.c o m-->
var x = "Language of the browser: " + navigator.browserLanguage;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: