SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question displaying non-english characters in javascript alert windows

    Hello all, Happy New Year.

    Is there a way to display non-engiish characters in a javascript alert window? I need to display what is (incorrectly) called an N with a tilde (˝) in a javascript alert window. I tried using the HTML coding for it: ñ but it displays it literally.

    Any hints?

    Thanks.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This works just fine for me in Mozilla Firefox 1.0 and Internet Explorer 6.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>Non-english character in alert message</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
     </head>
     
     <body>
      <script type="text/javascript">
       alert('˝');
      </script>
     </body>
    </html>
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... interesting. It does not work for me in Mozilla (firefox) mac or Safari. Haven't tested it on IE yet.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  4. #4
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your server send the correct charset declaration? It must match the character encoding used by your text editor. It's perfectly possible your editor saves files UTF-8 encoded. Anyway, this should work regardless of the encoding: alert("\u00f1")

  5. #5
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Saturn
    Does your server send the correct charset declaration? It must match the character encoding used by your text editor. It's perfectly possible your editor saves files UTF-8 encoded. Anyway, this should work regardless of the encoding: alert("\u00f1")
    I'm using Apache on my local machine. How can I check to see what encoding the server is sending?
    My editor (BBEdit) is saving the encoding as Western (Mac OS Roman). Should I change it to UTF-8 or something else?
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  6. #6
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With Firefox you can use Page Info (don't know what is called in Spanish in case you're using a localized version) to see the encoding. You can also set another encoding, it's in the View drop down menu. Mac Roman is not a good choice if you want to put your page on the net, ISO-8859-1 or UTF-8 are preferrable.


Bookmarks

Posting Permissions

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