<p>I am working on a web application, where I transfer data from the server to the browser in XML.</p>

<p>Since I'm danish, I quickly run into problems with the characters <code>æøå</code>.</p>

<p>I know that in html, I use the <code>"&amp;amp;aelig;&amp;amp;oslash;&amp;amp;aring;"</code> for <code>æøå</code>.</p>

<p>however, as soon as the chars pass through JavaScript, I get black boxes with <code>"?"</code> in them when using <code>æøå</code>, and <code>"&amp;aelig;&amp;oslash;&amp;aring;"</code> is printed as is.</p>

<p>I've made sure to set it to utf-8, but that isn't helping much.</p>

<p>Ideally, I want it to work with any special characters (naturally).</p>

<p>The example that isn't working is included below:</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;title&gt;Untitled Document&lt;/title&gt;
        &lt;script type="text/javascript" charset="utf-8"&gt;
            alert("&amp;aelig;&amp;oslash;&amp;aring;");
            alert("æøå");

        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>What am I doing wrong?</p>

<hr>

<p>Ok, thanks to Grapefrukts answer, I got it working.</p>

<p>I actually needed it for data coming from an MySQL server. Since the saving of the files in UTF-8 encoding only solves the problem for static content, I figure I'd include the solution for strings from a MySQL server, pulled out using PHP:</p>

<p><code>utf8_encode($MyStringHere)</code></p>

[{'answer_id': 60832, 'author': 'chryss', 'author_id': 5169, 'author_profile': 'https://Stackoverflow.com/users/5169', 'pm_score': 0, 'selected': False, 'text': '<p>This works as expected for me:</p>\n\n<pre><code>alert("&amp;aelig;&amp;oslash;&amp;aring;");\n</code></pre>\n\n<p>... creates an alert containing the string "&amp;aelig;&amp;oslash;&amp;aring;" whereas</p>\n\n<pre><code>alert("æøå");\n</code></pre>\n\n<p>... creates an alert with the non-ascii characters.</p>\n\n<p>Javascript is pretty utf-8 clean and doesn\'t tend to put obstacles in your way.</p>\n\n<p>Maybe you\'re putting this on a web server that serves it as ISO-8859-1? If you use Apache, in your Apache config file (or in .httaccess, if you can override), you should have a line</p>\n\n<pre><code>AddCharset utf-8 .js\n</code></pre>\n\n<p>(Note: edited to escape the ampersands... otherwise it didn\'t make sense.)</p>\n'}, {'answer_id': 60843, 'author': 'Eugene Yokota', 'author_id': 3827, 'author_profile': 'https://Stackoverflow.com/users/3827', 'pm_score': 1, 'selected': False, 'text': '<p>I get "&amp;aelig;&amp;oslash;&amp;aring;" for the first one and some junk characters for the next. Could it be that the javascript is not mangling (or <a href="http://en.wikipedia.org/wiki/Mojibake" rel="nofollow noreferrer">mojibake</a>) your letters but the alert dialog uses the system default font, and the font is incapable of displaying the letters?</p>\n'}, {'answer_id': 60851, 'author': 'grapefrukt', 'author_id': 914, 'author_profile': 'https://Stackoverflow.com/users/914', 'pm_score': 5, 'selected': True, 'text': "<p>Just specifying UTF-8 in the header is not enough. I'd bet you haven't saved your file as UTF-8. Any reasonably advanced text editor will have this option. Try that and I'm sure it'll work!</p>\n"}, {'answer_id': 67289, 'author': 'enricopulatzo', 'author_id': 9883, 'author_profile': 'https://Stackoverflow.com/users/9883', 'pm_score': 3, 'selected': False, 'text': '<p>You can also use <code>String.fromCharCode()</code> to output a character from a numeric entity.</p>\n\n<p>e.g. <code>String.fromCharCode( 8226 )</code> will create a bullet character.</p>\n'}, {'answer_id': 144878, 'author': 'Kevin Hakanson', 'author_id': 22514, 'author_profile': 'https://Stackoverflow.com/users/22514', 'pm_score': 5, 'selected': False, 'text': '<p>If you ever can\'t set the response encoding, you can use <code>\\u</code> escape sequence in the JavaScript string literal to display these characters.</p>\n\n<pre><code>alert("\\u00e6\\u00f8\\u00e5")\n</code></pre>\n'}, {'answer_id': 17870496, 'author': 'Kayun Chantarasathaporn', 'author_id': 2620771, 'author_profile': 'https://Stackoverflow.com/users/2620771', 'pm_score': 1, 'selected': False, 'text': '<p>I use the code like this with Thai language.  It\'s fine.</p>\n\n<p><code>$message</code> is my PHP variable.</p>\n\n<pre><code>echo("&lt;html&gt;&lt;head&gt;&lt;meta charset=\'utf-8\'&gt;&lt;/head&gt;&lt;body&gt;&lt;script type=\'text/javascript\'&gt;alert(\'" . $message . "\');&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;");\n</code></pre>\n\n<p>Hope this can help.  Thank you.</p>\n\n<p>(I cannot post image of what I did as the system said "I don\'t have enough reputation", so I leave the image, here. <a href="http://goo.gl/9P3DtI" rel="nofollow">http://goo.gl/9P3DtI</a> Sorry for inconvenience.)</p>\n\n<p>Sorry for my weak English.</p>\n'}]
['https://Stackoverflow.com/questions/60825', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1090/']