1

I have a requirement where I need to check for the language configured on a browser. I use

var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;

to check for the browser language.

This works fine on Firefox and chrome etc.

The problem arises on Internet explorer. When I debugged the javascript [using alert() :-)] the language was shown as en-EN eventhough i configured the browser with ge-GE.

Can anyone provide a solution for this.

Pavlo
  • 43,301
  • 14
  • 77
  • 113
DarthVivek
  • 11
  • 1
  • 3
  • 1
    The problem is `window.navigator.userLanguage` is IE only and it's the language set in Windows Control Panel - Regional Options and NOT browser language [(1)](http://stackoverflow.com/a/4079798/1092711). – Pavlo Jun 17 '13 at 10:05

2 Answers2

2

try this

 var language = window.navigator.userLanguage || window.navigator.language;
    alert(language); //works for IE,CHROME,FF,SAFARI.

see here

Community
  • 1
  • 1
Anuj
  • 1,496
  • 1
  • 18
  • 28
  • Hi Guys Thanks for all the response. However, I would like to point out that that the userLanguage, language etc returns the Operating language and not the browser language. So even if I change the language at IE to lets say French, the property still returns en-EN as the OS is in english.... Please note, this happens only on IE. Chrome and Firefox returns french code. – DarthVivek Jun 17 '13 at 10:47
  • did u refer the link in my post? – Anuj Jun 17 '13 at 10:49
  • for IE11 does not work – ses Mar 17 '15 at 15:52
0

You need to use navigator.userLanguage for IE and navigator.language for others

https://stackoverflow.com/a/4079798/406659

Community
  • 1
  • 1
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242