views:

35

answers:

5

i want to access the user browser settings and change the browser language, is this possible with java script code or no ? how can i access this ? sample code pleas ?

+1  A: 

This is definitely not possible using JavaScript on a web page.

A browser Extension might have the rights to change this - I'm not sure, it will also depend on the browser. However, building such an extension would require a fair amount of skill and work.

Pekka
+3  A: 

No that is not possible. How would you find it if you open a page, and your browser turns Arabic (or some other language you can't read)?

Lekensteyn
+1  A: 

This is impossible and a bad idea. A better idea is to detect the browser's language, which is possible to do reasonably well, and ask the user to change it (assuming the change is absolutely necessary).

Eric Mickelsen
this is not user friendly.
ammar
Neither is changing a user's browser language.
Andrew Dunn
+2  A: 

You can detect, but cannot set.

var lang = navigator.language || navigator.userLanguage;

// navigator.language     : Netscape & Firefox
// navigator.userLanguage : Internet Explorer


If you want to output different languages, the best way is to do it server-side. Either:

  • use an AJAX call to dynamically load the appropriate page
  • use a session variable to load the initial page correctly
vol7ron
+1  A: 

If what you actually want to do is detect the language the user is using, which is what you want to do, because nothing will annoy your visitors more that their browser preferences getting changed, on the server-side, read the Accept-Language HTTP request header that all modern browsers send, it should contain all the info you need. If it is absent, assume the language of your largest audience.

Check out RFC2616 Section 14.4 for more information on Accept-Language and it's use.

Andrew Dunn