且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无论如何,有使用JavaScript检测OS语言的方法吗?

更新时间:2022-02-03 08:57:31

没有跨浏览器的方法. Internet Explorer支持以下内容:

There is no cross-browser way to do this. Internet Explorer supports the following:

  • navigator.browserLanguage:浏览器语言
  • navigator.systemLanguage:Windows系统语言
  • navigator.userLanguage:Windows用户特定语言
  • navigator.browserLanguage: browser language
  • navigator.systemLanguage: Windows system language
  • navigator.userLanguage: Windows user-specific language

但是无法从其他任何浏览器访问这些设置(据我所知),所以不要使用它们:坚持使用标准navigator.language(与浏览器语言相对应)如果要维护跨浏览器功能.如果您确实使用它们,则会将您的网站绑定到特定的操作系统家族(例如Windows)和特定的浏览器(例如Internet Explorer).您真的要这样做吗?

But there is no way to access these settings from any other browsers (that I can tell) so don't use them: stick to the standard navigator.language (corresponding to the browser language) if you want to maintain cross-browser functionality. If you do use them you will tie your web site to a specific family of operating systems (i.e. Windows) and a specific browser (i.e. Internet Explorer). Do you really want to do this?

为什么浏览器语言不足以支持您的应用?

Why is the browser language insufficient for your application?