I’m generating dynamic HTML inside Delphi. I have no problem displaying UTF-8 strings inside the webpage body. I use HTMLEscape to encode regular strings (all the strings inside the string list are previously escaped).
The problem occurs inside the scripts (javascript) functions inside the dynamic page.
'<script language="javascript" charset="UTF-8">'+#10+
(...)
'function ProcessAddUserButton(){'+#10+
'alert("'+web_content_sl[70]+'");'+
'}'+#10+
For a string with the word “usuário” I get usuário in the alert box, but if I use the same string inside the HTML body it will display correctly. I’ve tried to include the charset inside the script definition as you can see above, but with no success. I don’t understand why I’m getting different results from the same string in the same page.
The META tag from the dynamic page is:
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'+#10+
As anyone experienced this?
The string is literally
"usuário". It will only show up “correctly” in a context that decodes html. You can also manually decode it with javascript but it’s easier just to pass the literal character from server in the first place instead of html encoding it.Here’s function to manually decode it in javascript: