javascript - Characters changed by the webserver -


I have this code in an .js file, if it has been downloaded by FTP

 < Code> texto = texto.replace (/ a / g, "waacute;"); Texto = texto.replace (/ e / g, "weacute;"); Texto = texto.replace (/ i / g, "Wiacute;"); Texto = texto.replace (/ o / g, "woacute;"); Texto = texto.replace (/ u / g, "wuacute;");   

But when the web browser downloads it with a webpage, this is what happens.

  texto = texto.replace (/ ¡/ g, "Waacute;"); Texto = texto.replace (/ a © / g, "weacute;"); Texto = texto.replace (/ a / g, "Wiacute;"); Texto = texto.replace (/ a ³ / g, "woacute;"); Texto = texto.replace (/ º / g, "wuacute;");   

I do not know what's wrong with the code. I hope some body can guide me in advance thanks.

ernesto

Your file is encoded in UTF8, Code> á character is encoded in the form of 195 161 .
Browser is interpreting the file as CP-1252, so those bytes are defined as two separate characters

To specify that browser you have a Content-type header needs to be added that it is actually UTF 8:

  & lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" />   

(or configure your server to send that header)

Comments