[javascript] How to get the browser language using JavaScript

Possible Duplicate:
JavaScript for detecting browser language preference

I want to detect the language of the browser that is entering my site, if it's En or Fr. So I can redirect to the En page or the other page.

Also, can I detect mobile language?

This question is related to javascript

The answer is


The "JavaScript" way:

var lang = navigator.language || navigator.userLanguage; //no ?s necessary

Really you should be doing language detection on the server, but if it's absolutely necessary to know/use via JavaScript, it can be gotten.