问题描述
我将通过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
这篇关于如何检测用户的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!