在Javascript中将编码从UTF-8更改为ISO-8859-2 [英] Change encoding from UTF-8 to ISO-8859-2 in Javascript
问题描述
我想在Javascript中将字符串编码从UTF-8更改为ISO-8859-2。我该如何做?
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 my site and puts it on his. This script creates div and puts into div widget contents with text.
如果目标网站采用UTF-8编码,它可以正常工作。但是当它在ISO-8859-2比在UTF-8编码的文本在现场显示与ISO-8859-2,因此我看到垃圾。
If target website is in UTF-8 encoding - it works fine. But when it is in ISO-8859-2 than text that is encoded in UTF-8 is displayed on site with ISO-8859-2 and as a result I see trash.
推荐答案
而不是使用eg在您的JavaScript代码中使用\"ĉ,使用Unicode转义(例如\\\ĉ)。
Instead of using e.g. "ĉ" in your JavaScript code, use Unicode escapes such as "\u0109".
这篇关于在Javascript中将编码从UTF-8更改为ISO-8859-2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!