Alerting Chinese characters - can it be done?

Discussion in 'Javascript' started by Laser Lips, Jul 6, 2010.

  1. Laser Lips

    Laser Lips Guest

    Does anyone know if I can print Chinese chracters ?

    alert("Çë×¢ÒâÊý¾Ý½«ÒÔ");

    Thanks,
    Graham
     
    Laser Lips, Jul 6, 2010
    #1
    1. Advertising

  2. Laser Lips wrote:
    > Does anyone know if I can print Chinese chracters ?
    >
    > alert("请注æ„æ•°æ®å°†ä»¥");


    Firefox 3 does render those characters in a alert dialog window on a
    German edition of Windows XP Professional. However IE 8 on the same
    system only renders square boxes for each character.
    Safari and Opera also manage to display those characters in an alert
    dialog window.


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jul 6, 2010
    #2
    1. Advertising

  3. Laser Lips

    Laser Lips Guest

    Thanks for the reply. I only need to support IE if anyone has an IE
    solution.

    Graham
     
    Laser Lips, Jul 6, 2010
    #3
  4. Martin Honnen, Jul 6, 2010
    #4
  5. Laser Lips

    Laser Lips Guest

    On Jul 6, 12:56 pm, Martin Honnen <> wrote:
    > Laser Lips wrote:
    > > Thanks for the reply.  I only need to support IE if anyone has an IE
    > > solution.

    >
    > If the alert dialog does not show such characters then with IE you could
    > define your own dialog contents with HTML and show it using showModalDialoghttp://msdn.microsoft.com/en-us/library/ms536759(v=VS.85).aspx
    >
    > --
    >
    >         Martin Honnen
    >        http://msmvps.com/blogs/martin_honnen/



    Actually, I necessarily need to alert the characters. I just find
    that JavaScript doesn’t seem to be able to handle the characters. I'm
    going to be writing them to an element on the page, but I can't seem
    to do anything with them once JavaScript as hold of them. They turn
    into '?' straight away. Alerting is probably the most basic thing I
    could think of doing with them.
    If I use document.write it still writes questions marks.

    Graham Vincent
     
    Laser Lips, Jul 6, 2010
    #5
  6. Laser Lips wrote:

    > Actually, I necessarily need to alert the characters. I just find
    > that JavaScript doesn’t seem to be able to handle the characters. I'm
    > going to be writing them to an element on the page, but I can't seem
    > to do anything with them once JavaScript as hold of them. They turn
    > into '?' straight away. Alerting is probably the most basic thing I
    > could think of doing with them.
    > If I use document.write it still writes questions marks.


    Does the browser render Chinese characters correctly when you insert
    them statically in your HTML document? Or does that already result in
    question marks?

    Is a font installed on that system that has glyphs for those characters?

    Is the Javascript code embedded inside of an HTML document or is it
    inside a separate .js file? What's the encoding of the HTML document or
    the .js file?


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jul 6, 2010
    #6
  7. Laser Lips

    Laser Lips Guest

    On Jul 6, 2:14 pm, Martin Honnen <> wrote:
    > Laser Lips wrote:
    > > Actually, I necessarily need to alert the characters.  I just find
    > > that JavaScript doesn t seem to be able to handle the characters. I'm
    > > going to be writing them to an element on the page, but I can't seem
    > > to do anything with them once JavaScript as hold of them.  They turn
    > > into '?' straight away.  Alerting is probably the most basic thing I
    > > could think of doing with them.
    > > If I use document.write it still writes questions marks.

    >
    > Does the browser render Chinese characters correctly when you insert
    > them statically in your HTML document? Or does that already result in
    > question marks?
    >
    > Is a font installed on that system that has glyphs for those characters?
    >
    > Is the Javascript code embedded inside of an HTML document or is it
    > inside a separate .js file? What's the encoding of the HTML document or
    > the .js file?
    >
    > --
    >
    >         Martin Honnen
    >        http://msmvps.com/blogs/martin_honnen/


    Hi Martin, the browser renders the Chi9nese characters correclty if I
    put them in statically
    The JS file is external. What encoding should I use to save the file?

    Thanks
    Graham
     
    Laser Lips, Jul 6, 2010
    #7
  8. Laser Lips wrote:

    > Hi Martin, the browser renders the Chi9nese characters correclty if I
    > put them in statically
    > The JS file is external. What encoding should I use to save the file?


    I would use UTF-8. But is more important that the server sends a HTTP
    Content-Type header with a charset parameter indicating the encoding,
    whatever the encoding is. Or at least use a charset attribute on the
    script element to indicate the encoding e.g. if the script file is UTF-8
    encodeded then use
    <script type="text/javascript" src="file.js" charset="UTF-8"></script>
    so that the browser knows the encoding. That way at least document.write
    should work without problems. Whether IE allows you to use Chinese
    characters in a alert dialog window I am not sure as my test here failed.


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jul 6, 2010
    #8
  9. Laser Lips

    Laser Lips Guest

    On Jul 6, 2:31 pm, Martin Honnen <> wrote:
    > Laser Lips wrote:
    > > Hi Martin, the browser renders the Chi9nese characters correclty if I
    > > put them in statically
    > > The JS file is external.  What encoding should I use to save the file?

    >
    > I would use UTF-8. But is more important that the server sends a HTTP
    > Content-Type header with a charset parameter indicating the encoding,
    > whatever the encoding is. Or at least use a charset attribute on the
    > script element to indicate the encoding e.g. if the script file is UTF-8
    > encodeded then use
    >    <script type="text/javascript" src="file.js" charset="UTF-8"></script>
    > so that the browser knows the encoding. That way at least document.write
    > should work without problems. Whether IE allows you to use Chinese
    > characters in a alert dialog window I am not sure as my test here failed.
    >
    > --
    >
    >         Martin Honnen
    >        http://msmvps.com/blogs/martin_honnen/


    OK, if I save a HTML file as Unicode and then simply do a
    document.write OR an alert("æ„æ•°æ®"); I get Chinese characters.
    I think this solves the problem.
    One problem remains and that's that the HTML pages and the JavaScript
    is created with software called CACHE (Intersystems).
    Just need to find out how to tell the write mechanism to use Unicode
    and I think the problem is solved.
    Cheers for the suggestions.
    Graham Vincent
     
    Laser Lips, Jul 6, 2010
    #9
    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. omegaman
    Replies:
    1
    Views:
    597
    omegaman
    Sep 21, 2004
  2. Peter Aitken

    Alerting the user from code behind

    Peter Aitken, Jul 31, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    124
    Peter Aitken
    Aug 2, 2004
  3. susie

    Sample for Alerting user

    susie, Dec 3, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    105
  4. Farrel Lifson

    RCAP - Common Alerting Protocl for Ruby

    Farrel Lifson, Nov 3, 2009, in forum: Ruby
    Replies:
    1
    Views:
    112
    Farrel Lifson
    Nov 3, 2009
  5. Farrel Lifson
    Replies:
    0
    Views:
    117
    Farrel Lifson
    Apr 6, 2011
Loading...

Share This Page