Browser Converts No ASCII for JS Text Node or any Text Attribute

V

vunet.us

Browsers convert my ASCII fine when webpage is set to
charset=iso-8859-1.
However, my AJAX app has too many cases with

var myASCII = "ü";
document.createTextNode(myASCII);

In this case or similar, such as option.text = myASCII; for select
object, browsers fail to convert ASCII to HTML.

What can be done? Do I need to rewrite all cases to use innerHTML
instead of createTextNode, etc.?
Thanks
 
M

Martin Honnen

Browsers convert my ASCII fine when webpage is set to
charset=iso-8859-1.
However, my AJAX app has too many cases with

var myASCII = "ü";
document.createTextNode(myASCII);

In this case or similar, such as option.text = myASCII; for select
object, browsers fail to convert ASCII to HTML.

The createTextNode method takes a DOM string, in JavaScript that is
simply a JavaScript string so try
document.createTextNode("ü")
or
document.createTextNode(String.fromCharCode(0xFC))
or
document.createTextNode("\u00FC")

The ü syntax is a numeric character reference meant for an HTML
or XML parser. createTextNode does not do any HTML or XML parsing.
 
V

vunet.us

The createTextNode method takes a DOM string, in JavaScript that is
simply a JavaScript string so try
document.createTextNode("ü")
or
document.createTextNode(String.fromCharCode(0xFC))
or
document.createTextNode("\u00FC")

The ü syntax is a numeric character reference meant for an HTML
or XML parser. createTextNode does not do any HTML or XML parsing.

Yes, Unicode works well: document.createTextNode("\u00FC"). However,
my strings look like:

var myASCII = "Do not remove text ü and do not remove text,
blah blah";
document.createTextNode(myASCII);

and there are plenty of different strings containing all possible
ASCII values. What would you recommend in that case. Is it possible to
convert all ASCII to Unicode, then?
 
M

Martin Honnen

var myASCII = "Do not remove text ü and do not remove text,
blah blah";
document.createTextNode(myASCII);

and there are plenty of different strings containing all possible
ASCII values. What would you recommend in that case. Is it possible to
convert all ASCII to Unicode, then?

ASCII is a subset of Unicode. As said, ü is a numeric character
reference to be parsed by an HTML or XML parser. That has nothing to do
with ASCII. If you have such character references then you need to use
an HTML parser for instance by setting innerHTML of an HTML element node.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top