Java and JavaScript (.js) source files can use any character encoding. If one programmer uses UTF-8 and the other ISO encoding, there is a chance you will end with something like "Ren�" or "René" instead of "René". The most reliable way to avoid all conversion errors is to encode all special characters with escape sequences. JavaScript allows both hex (e.g. \xFF
) and Unicode escape sequences (e.g. \u0100
) in string literals while Java allows Unicode escape sequences only.
Click here to see it in action.
Tested with Opera, Firefox and Internet Explorer 8 (insufficient CSS support, but it works).
I know. Even if it's possible, such characters should never appear in source code files. What we can do is replacing
\t
with\0
to avoid bad conversions. But I'm not sure if this works in all browsers. Added it to my tests suite.