Characters changed by the webserver
I have this code in an .js file, if it is downloaded via ftp
texto=texto.replace(/á/g,"Waacu开发者_如何学编程te;");
texto=texto.replace(/é/g,"Weacute;");
texto=texto.replace(/í/g,"Wiacute;");
texto=texto.replace(/ó/g,"Woacute;");
texto=texto.replace(/ú/g,"Wuacute;");
but when the web browser downloads it with the webpage, that is what it gets.
texto=texto.replace(/á/g,"Waacute;");
texto=texto.replace(/é/g,"Weacute;");
texto=texto.replace(/Ã/g,"Wiacute;");
texto=texto.replace(/ó/g,"Woacute;");
texto=texto.replace(/ú/g,"Wuacute;");
I don't know what's wrong with the code. I hope some body can guide me. Thanks in advance.
ernesto
You've a UTF-8 file that's being parsed as if it was some 8-bit fixed Latin format.
Ideally, send the correct headers from the server (just how to do that depends on server and/or server-side scripting language). As a back up add <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
though it's sucky to have it disagree with the server.
Alternatively, use unicode escapes in the javascript, and you become immune to all of this.
Your file is encoded in UTF8, so the á
character is encoded as 195 161
.
The browser is interpreting the file as CP-1252, so those bytes are interpreted as two different characters
You need to add a Content-Type
header to tell that browser that it's really UTF8:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
(Or configure your server to send that header)
精彩评论