Вам необходимо использовать decodeURIComponent
в дополнение к escape
до go в / из UTF8 / ISO-8859-1
См. эту статью для получения дополнительной информации о ней .
Декодировать UTF-: fixedstring = decodeURIComponent(escape(utfstring));
Декодировать ISO-8859-1: utfstring = unescape(encodeURIComponent(originalstring));
Чтобы узнать, является ли строка UTF-8:
var fixedstring;
try{
// If the string is UTF-8, this will work and not throw an error.
fixedstring=decodeURIComponent(escape(badstring));
}catch(e){
// If it isn't, an error will be thrown, and we can assume that we have an ISO string.
fixedstring=badstring;
}