Get Client Browser preferences

I am developing a web interface, which should work for multiple languages.
I am forcing the language to be displayed on the page with Header Environmenal Encoding META setting.
I would like to find a way to see if end user changes browser language from default so that I could adjust my script and during the next request, send the META option to set whatever user selected previously.

I can ask a user to select a language from the Drop-down box of course, but I would like to see a way to catch it when the browser's setting is changed (example: user selects "View" -> "Encoding" -> Unicode (UTF-8) on the browser menu).

Anybody knows a way to catch it?

Thank You.
LVL 6
sstoukAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
As you have posted this in "CGI Programming", are the pages generated by a CGI program?  If so, then don't rely on the META tag for setting the encoding as it will be overwritten by the http header.

There's no 100% reliable way to detect the current settings.  The closest you can get is using some Javascript.
0
ahoffmannCommented:
if ($ENV{'HTTP_ACCEPT_LANGUAGE'} == 'en') { .. }
0
sstoukAuthor Commented:
thanks for your replies...
Tintin,
I am generating the Http header myself using cgi perl script.
And the question is about How to get the encoding setting.
Can you point me to some example that I could use if you know of any JavaScript that could help?

ahoffmann,

This just tells me the language, not the encoding.
I can perfectly get All the environmental settings using this method, but there's nothing there that would tell me the encoding.

the language is russian but it has at least 4 different encodings windows-1251, koi8-r etc...

I need this for the e-mail application that lists all the headers from incoming e-mail messages, recieved from different systems. They might send the message in different formats of the same language.

If I know what the current browser's encoding is, I can translate all the wrong encodings to the one, user would see properly.

Still,
How to get the encoding, set on the browser currently?

thanks again.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ahoffmannCommented:
hmm, koi8- etc.  think you're trapped
Which encoding is used by the browser is a browsr setting and will not be written in the request's header, usually, unfortunately.
You need to provide the correct encoding in your Web-Site.
Have a look at most common sites in .ru and you'll see that most offer an link to switch from one encoding to another.
A well programmed site even may offer this as CSS.

If you need to know the browser's prefered encoding, the link method is the most reliable, 'cause you then can use the URL and/or REFERER to check which encoding is currently used.
Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sstoukAuthor Commented:
This method - selectible form drop-down field I already implemented and it works, however I wanted to do it in the background, rather than complicate end-users with extra questions like "what is this encoding for...???"

If there is no other method, ahoffmann, you get the points. I just want this question to remain posted for some time to allow more experts to look at it.

Thanks.
0
ahoffmannCommented:
beside HTTP_ACCEPT_LANGUAGE you can check HTTP_ACCEPT_CHARSET
it contains a semicolon-separated list of charsets.
If it contains koi8-r, koi8-u, windows-1251, iso-8859-5, ibm-855, iso-ir-111, cp-866 (probably some others) you got what you want.
0
sstoukAuthor Commented:
This is not a reliable way.
Some browsers do not support HTTP_ACCEPT_CHARSET variable...

Well, the solution here is posted by ahoffmann
Here's a solution:
"hmm, koi8- etc.  think you're trapped..."

And this is correct.
My research did not provide any answers and I am giving an end-user the drop-down list of selectable encodings which my script remembers and sets the web page to user's preference.

The script is  an e-mail client and e-mails are received from different servers, so it's up to the end-user to change the encoding and see a portion of e-mail subject lists in correct encoding, then to change the encoding and see the other half.

There is no other solution here, unless I provide the automatic recognition and encoding change of the incorrect e-mail messages... but this is too much work for now.... it's not commercial yet.

Thank You all for participating ...

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.