Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / June 2007



Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vunet.us@gmail.com - 29 Jun 2007 16:54 GMT
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
Martin Honnen - 29 Jun 2007 17:01 GMT
> Browsers convert my ASCII fine when webpage is set to
> charset=iso-8859-1.
[quoted text clipped - 5 lines]
> 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.

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

vunet.us@gmail.com - 29 Jun 2007 17:22 GMT
> vunet...@gmail.com wrote:
> > Browsers convert my ASCII fine when webpage is set to
[quoted text clipped - 22 lines]
>         Martin Honnen
>        http://JavaScript.FAQTs.com/

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?
Martin Honnen - 29 Jun 2007 17:28 GMT
>> The ü syntax is a numeric character reference meant for an HTML
>> or XML parser. createTextNode does not do any HTML or XML parsing.

> var myASCII = "Do not remove text ü and do not remove text,
> blah blah";
[quoted text clipped - 3 lines]
> 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.

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.