0
votes

My webpage has some chinese characters. When the browser text encoding is "Unicode" everything is fine. But when I change it to "Western" the chinese characters are getting messy.

I want the page to display in UTF-8 irrespective of the browser encoding. How to do it?

The response header received for the JSP has Content-Type: "text/html;charset=UTF-8". When I check the response in the network tab, it is proper(in UTF-8). Also JSP has

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Even with all these charset mentions, the browser text encoding is taking preference. Can this be overridden? Can the page always be in "UTF-8" regardless of the browser encoding?

Note: The browser I checked is Firefox.

Text boxes are pre-populated with chinese characters from the server.

This is when the browser text encoding is "Unicode".

enter image description here

document.charset is "UTF-8"


This is when the browser text encoding is "Western".

enter image description here

document.charset is "windows-1252"

enter image description here

Please help.

1
What normal user is going to your site, sees correct text, explicitly selects a different encoding and then expects anything but mojibake? This really isn't a problem worth worrying about. That setting typically also resets with every new page/domain, it's not something that sticks around as default. - deceze

1 Answers

2
votes

I want the page to display in UTF-8 irrespective of the browser encoding. How to do it?

You can't.*

Manually selecting an encoding in the browser's encoding menu is supposed to override anything that the web site is saying about what the encoding should be.

You can't prevent this, and neither should you.

Anyone forcing the browser to use an encoding that the web site doesn't support is acting on their own responsibility.

* well, apart from displaying all text in images. Or in a Flash movie. :)