如何检测用户的语言[重复]

时间:2023-01-30 00:08:26

This question already has an answer here:

这个问题在这里已有答案:

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.

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

What I have found is this:

我发现的是:

window.navigator.language;

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

它检测浏览器的语言,它始终是En-us。

How could I solve that?

我怎么能解决这个问题?

1 个解决方案

#1


23  

You can try like this:-

你可以尝试这样: -

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

navigator.userLanguage works for IE

navigator.userLanguage适用于IE

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

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

Also check out this Thread

另请查看此主题

#1


23  

You can try like this:-

你可以尝试这样: -

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

navigator.userLanguage works for IE

navigator.userLanguage适用于IE

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

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

Also check out this Thread

另请查看此主题