Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Question Unicode Display question

    How do I display the Unicodes that do not show up in the failed section of this code?
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Unicode Display Test </title>
    <meta charset="utf-8">
    </head>
    <body>
    <p id="test"></p>
    
    <script type="text/javascript">
    var str = '<b>Unicode test</b><br>';
    str += '&#xb0;'+' - xb0 (degree)<br>';
    str += '&#xb1;'+' - xb1 (plus_minus)<br>';
    str += '&#xb2;'+' - xb2 (superscript 2)<br>';
    str += '&#xb3;'+' - xb3 (superscript 3)<p>';
    str += '&#xb5;'+' - xb5 (mu)<br>';
    
    str += '&#x3A0;'+' - x3A0 (PI)<p>';
    
    // failed attempts
    /*
    str += '&#xc3b8;'+' - c3b8 <br>';
    str += '&#xcf80;'+' - cf80 <br>';
    
    str += '\uc3b8'+' - \c3b8 <br>';
    str += '\ucf80'+' - \cf80 <br>';
    */
    
    var n = 0xc3b8;  str += '&#'+n+'; - 0xc3b8 (Theta)<br>';
        n = 0xcf80;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
    document.getElementById('test').innerHTML = str;
    </script>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Have you tried doing all of them like the last two?

    Code:
    var n = 0xc3b8;  str += '&#'+n+'; - 0xc3b8 (Theta)<br>';
         n = 0xcf80;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Arrow

    Quote Originally Posted by WolfShade View Post
    Have you tried doing all of them like the last two?

    Code:
    var n = 0xc3b8;  str += '&#'+n+'; - 0xc3b8 (Theta)<br>';
         n = 0xcf80;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
    Yes.

    The code above the comment "// failed attempts" works and displays fine.

    There are 3 different attempts to display the other characters.
    The attempt you sited is just the last attempt that displays chinese (???) characters.
    Try and test the code as a local file. It is easier to see the problem than to explain it.
    I am able to display some of the codes correctly, but not the ones below the comment.

    Edited code for your question:
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Unicode Display Test </title>
    <meta charset="utf-8">
    </head>
    <body>
    <p id="test"></p>
    
    <script type="text/javascript">
    var str = '<b>Unicode test</b><br>';
    str += '&#xb0;'+' - xb0 (degree)<br>';
    str += '&#xb1;'+' - xb1 (plus_minus)<br>';
    str += '&#xb2;'+' - xb2 (superscript 2)<br>';
    str += '&#xb3;'+' - xb3 (superscript 3)<p>';
    str += '&#xb5;'+' - xb5 (mu)<br>';
    
    str += '&#x3A0;'+' - x3A0 (PI)<p>';
    
    // failed attempts
    /*
    str += '&#xc3b8;'+' - c3b8 <br>';
    str += '&#xcf80;'+' - cf80 <br>';
    
    str += '\uc3b8'+' - \c3b8 <br>';
    str += '\ucf80'+' - \cf80 <br>';
    */
    
    var n = 0xc3b8;  str += '&#'+n+'; - 0xc3b8 (Theta)<br>';
        n = 0xcf80;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
      str += '<br>';
        n = 0xb0;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
        n = 0xb1;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
        n = 0xb2;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
        n = 0xb3;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
        n = 0xb5;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
        n = 0x3a0;  str += '&#'+n+'; - 0xcf80 (pi)<br>';
    
    document.getElementById('test').innerHTML = str;
    </script>
    </body>
    </html>
    Last edited by jmrker; 05-07-2013 at 09:42 PM.

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    To properly display Unicode you need to use a font which displays those characters, you may have to use something like @fontface to include the font, you may have to specify the language, and XML has better support for Unicode than HTML. Otherwise your results will be haphazard.

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Question

    Quote Originally Posted by DrDOS View Post
    To properly display Unicode you need to use a font which displays those characters, you may have to use something like @fontface to include the font, you may have to specify the language, and XML has better support for Unicode than HTML. Otherwise your results will be haphazard.
    I guess I'm confused.
    I thought the charset="utf-8" assignment in the meta tag did that.
    Where are the characters coming from in the sample script?
    Is the @fontface you are referring to a part of the CSS definition?

  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    utf-8 refers to the way the data is encoded for being sent from the host to the client machine. When it arrives at the client it still has to be interpreted by a font that can render it, and in the proper language.

    I checked your script in three browsers. Firefox rendered the Chinese correctly, Opera and Chrome did not render them.

    If you need a font family that can render in many languages, a good one to start with is the Gentium family. It's free, nice looking, and supports many characters in many languages.

  • #7
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Lightbulb

    I found a partial answer to my question.

    What I really was looking for what the math symbols for phi, theta, square-root & cube-root,
    but I kept getting some unknown language (chinese???) characters.

    The following gives me what I want without doing anything different with the "charset=utf-8" meta tag setting.

    I still have some questions concerning the character sequence to generate the symbol,
    but now I have at least one to 5 possibilities.

    See code below to see what I have found.
    (Having some difficulty showing character code without showing character being substituted,
    hence the commented code about "without spaces")

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Untitled </title>
    
    </head>
    <body>
    <script type="text/javascript">
    // Modified from: http://www.javascripter.net/faq/mathsymbols.htm
    
    var str = '';
        str += '\u20AC ';               // 
        str += ' ';              //   str += '& #8364; ';  without spaces
        str += '&euro; ';               // 
        str += unescape('%u20AC');      // 
        str += decodeURI('%E2%82%AC');  // 
        str += '<br>';
    
        str += '\xB1 ';                 // 
        str += ' ';               //   str += '& #177;';  without spaces
        str += '&plusmn; ';             // 
        str += unescape('%B1');         // 
        str += decodeURI('%C2%B1');     // 
        str += '<br>';
    
    //    str += '\uC2B8';               // phi (no good) - language ???
    //    str += '㲸';             // phi (no good) - language ???  str += '& #15544;'; without spaces
    //    str += unescape('%uC3B8');     // phi (no good) - language ???
        str += decodeURI('%C3%B8');    // phi
        str += '<br>';
    
    //    str += '\uCF80';               // pi  (no good) - language ???
    //    str += '쾀';             // pi  (no good) - language ???   str += '& #53120;'; without spaces
    //    str += unescape('%uCF80');     // pi  (no good) - language ???
        str += decodeURI('%CF%80');    // pi
        str += '<br>';
    
        str += '√ ';              // sqrt  str += '& #8730';  without spaces
        str += '&radic; ';              // sqrt
        str += '<br>';
    
        str += '\xb2√ ';          // sqrt  str += '\xb2& #8730; '; without spaces
        str += '\xb2&radic; ';          // sqrt
        str += '<br>';
    
        str += '\xb3√ ';          // cube-root  str += '\xb3& #8730; '; without spaces
        str += '\xb3&radic; ';          // cube-root
        str += '<br>';
    
    document.write(str);
    </script>
    
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •