[多浏览器兼容]Javascript获取浏览器语言的缺陷

There is a limitation for JavaScript to detect browser language(here).

1) For FF

FF support JS “navigator.language” to get the browser languages. So we can use JS to get FF language.

2) For Chrome 

There are 3 language selections for Chrome(more details here) – “Display language”, “Spell-checker language”, and “Webpage language”. The web page’s language is determined by Chrome “Webpage language”. But there is no interface to detect “Webpage language” for JS. Normally we use JS “navigator.language” to detect “Display language”. So user should set Chrome “Display language” the same as “Webpage language” to get proper language display.

3) For IE 

IE version lower than 11.0 don’t support “navigator.language”(here). So there is no way to get IE(<11.0) language. But IE support “navigator.userLanguage” to get OS language. So normally JS get IE language by “userLanguage” since most user’s OS language is the same as OS language.


Some 3rd party lib such as i18next. The lib detect language from navigator by the code below at function detectLanguage() for FF/Chrome/IE.

  • detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage;

i18next-1.7.4.js

So detectLanguage() cannot get the browser language of IE & Chrome. This is the root cause of IE & Chrome language confusion. Anyway, most of the front-end JS program get browser language by navigator since most of the user OS language is the same as browser language.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值