How to get the browser language using JavaScript [duplicate]
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?
Solution 1:
Try this script to get your browser language
<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage;
alert ("The language is: " + userLang);
</script>
Cheers
Solution 2:
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.