You are here: irt.org | FAQ | JavaScript | Misc | Q21 [ previous next ]
Depending on whether the users browser is using a particular language then it is possible to detect this by analysing the navigator.userAgent for characters with right angle brackets: [ ].
For example, on my browser the userAgent returns the following:
Mozilla/4.0 [en] (Win95; I)
This can be retrieved using:
<script language="JavaScript"><!-- var start = navigator.userAgent.indexOf('['); if (start > -1) { var end = navigator.userAgent.indexOf(']'); if (end > -1) { var language = navigator.userAgent.substring(start+1,end); document.write("<P>Language = " + language); } } //--></script>
Since this was answered, you can now make use of the Navigator objects language or browserLanguage property, i.e. navigator.language, navigator.browserLanguage. See http://www.irt.org/articles/js082 for further details.