如何检测用户的语言

如何检测用户的语言

本文介绍了如何检测用户的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将通过javascript检测用户的键盘语言。我得到了一个应该用波斯语字符填充的输入(文本类型)。因此,如果语言不是波斯语,我需要警告用户更改他们的键盘语言。



我发现的是这样的:

  window.navigator.language; 

检测浏览器的语言始终为En-us。

我怎么能解决这个问题?

解决方案

您可以尝试这样: - $ / $>
$ b

  var language = window.navigator.userLanguage || window.navigator.language; 
alert(language);

navigator.userLanguage 适用于IE



window.navigator.language 适用于firefox / opera / safari

另请参阅


I'm going to detect user's keyboard language by javascript. I got a input (type of text) which should be filled with Persian characters. So, I need to alarm users change their keyboard language if their language is not Persian.

What I have found is this:

window.navigator.language;

which detects browser's language which is always En-us.

How could I solve that?

解决方案

You can try like this:-

var language = window.navigator.userLanguage || window.navigator.language;
alert(language);

navigator.userLanguage works for IE

window.navigator.language works for firefox/opera/safari

Also check out this Thread

这篇关于如何检测用户的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:02