Window navigator.language 属性
实例
获取浏览器语言:
<!DOCTYPE html>
<html>
<body>
<h2>language 属性</h2>
<p id="demo">
<script>
let language = navigator.language;
document.getElementById("demo").innerHTML = "浏览器语言: " + language;
</script>
</body>
</html>
定义与用法
language
属性返回浏览器语言。
language
属性是只读的。
语法
navigator.language
返回值
类型 | 描述 |
A string | 浏览器语言: 比如: "en", "en-US", "de", "fr"。 |
更多实例
显示所有 navigator 属性:
<!DOCTYPE html>
<html>
<body>
<h2>所有 navigator 属性</h2>
<div id="demo"></div>
<script>
let text = "<p>Browser CodeName: " + navigator.appCodeName + "</p>" +
"<p>Browser Name: " + navigator.appName + "</p>" +
"<p>Browser Version: " + navigator.appVersion + "</p>" +
"<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>" +
"<p>Browser Language: " + navigator.language + "</p>" +
"<p>Browser Online: " + navigator.onLine + "</p>" +
"<p>Platform: " + navigator.platform + "</p>" +
"<p>User-agent header: " + navigator.userAgent + "</p>";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
浏览器支持
navigator.language
所有浏览器都支持:
属性 | |||||
---|---|---|---|---|---|
navigator.language | Yes | Yes | Yes | Yes | Yes |