javascriptutf-8iso-8859-1fromcharcode

Javascript String.fromCharCode() latin1 encoding issue


I don't know if I can write a fiddle for this so I'll just try to explain this as well as I possibly can.

We have an application where we've written an editor. We need to check some grammar rules on strings/tokens that are being entered into the editor.

However, when using String.fromCharCode(190), instead of getting a "." as in utf-8 we get a "¾" from latin1.

I've checked whether or not we set latin1 as the default encoding somewhere but I've been unable to find anything.

Can anyone point me into the right direction or possibly find a solution for this issue?

The HTML charset is UTF-8 as well as the javascript file (this only adds to my confusion haha).


Solution

  • As per the doc, String.fromCharCode() returns a unicode character. It's got nothing to do with encoding. "¾" is the unicode character for 190, that's it. http://unicode-table.com/