Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q21 Can I detect the language set in user's browser?

irt.org | Knowledge Base | JavaScript | Misc | Q21 [ previous next ]

Q21 Can I detect the language set in user's browser?

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/index.htm for further details.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.