Skip to content Skip to sidebar Skip to footer

Change Encoding From UTF-8 To ISO-8859-2 In Javascript

I would like to change string encoding from UTF-8 to ISO-8859-2 in Javascript. How can I do it? I need it because I've designed a widget. User just copies < script > tag from

Solution 1:

Instead of using e.g. "ĉ" in your JavaScript code, use Unicode escapes such as "\u0109".


Solution 2:

If you're in control of the output, you can replace all special characters with unicode escapes (e.g. \u00e4 for ä). The browser can interpret it correctly regardless of document encoding.

The easiest way to do this would be to put the string into a JSON encoder. Both PHP's and Ruby's does that. Don't know about other implementations though.

Another solution that might work is to add charset="utf-8" to the <script> tag.


Solution 3:

I suppose you just need to convert your wdiget from UTF-8 to ISO-8859-2 and provide 2 versions of script.


Post a Comment for "Change Encoding From UTF-8 To ISO-8859-2 In Javascript"