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

Discussion in 'Javascript' started by vunet.us@gmail.com, Jun 29, 2007.

  1. Guest

    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
     
    , Jun 29, 2007
    #1
    1. Advertising

  2. wrote:
    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 29, 2007
    #2
    1. Advertising

  3. Guest

    On Jun 29, 12:01 pm, Martin Honnen <> wrote:
    > wrote:
    > > 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.
    >
    > --
    >
    > 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?
     
    , Jun 29, 2007
    #3
  4. wrote:

    >> 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";
    > 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.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 29, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,671
  2. CB
    Replies:
    1
    Views:
    614
    Johannes Koch
    Oct 2, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,521
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    1
    Views:
    589
    Martin Honnen
    May 8, 2007
  5. Manoj
    Replies:
    0
    Views:
    586
    Manoj
    Nov 4, 2008
Loading...

Share This Page