Solved

Get Client Browser preferences

Posted on 2003-10-29
7
226 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:sstouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 9654200
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9662953
if ($ENV{'HTTP_ACCEPT_LANGUAGE'} == 'en') { .. }
0
 
LVL 6

Author Comment

by:sstouk
ID: 9664278
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 51

Accepted Solution

by:
ahoffmann earned 125 total points
ID: 9665450
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
 
LVL 6

Author Comment

by:sstouk
ID: 9666776
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9669311
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
 
LVL 6

Author Comment

by:sstouk
ID: 9744808
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

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question