2

我有一个警告框,我想显示一些冰岛语文本,但没有显示

<script>
function check() {
alert("Þú verður að vera skráð/ur inn til þess að senda skilaboð");
}
</script>

它正在显示警报框,但文本混乱​​:(

Þú verður að vera skráð/ur inn til þess að senda skilaboð

请提供任何帮助:(

4

4 回答 4

6
于 2012-06-21T13:32:29.993 回答
2

Let's do it in html5 manner :)

<!doctype html>
<html>
   <head>
       <meta charset = "utf-8" />
   </head>
于 2012-06-21T13:37:08.277 回答
0

encoding hazards my best guesses: check if...

  1. the js-file is stored properly encoded (UTF8) on your server
  2. the server delivers the JS file with proper encoding header (HTTP/1.1 about encoding)
  3. ... @Diodeus is right
于 2012-06-21T13:34:50.687 回答
0

What you see displayed by the alert is UTF-8 encoded text misinterpreted as windows-1252 encoded. (Windows-1252 is a Microsoft extension to ISO-8859-1.)

If your pages are ISO-8859-1 encoded, as they apparently are, then this applies to the script element content too. There is something odd going if the code you posted does not work. Are you sure the element is really inside a normal page of yours where Icelandic characters work OK? You should not try this fix the situation with a shot in the dark like changing encodings without knowing what is going on.

I’m just making a guess: the alert() invocation is really in an external .js file, which is UTF-8 encoded but treated by browsers as windows-1252 encoded. Then there are two alternative fixes: 1) open that file in an editor and save it as windows-1252 or ISO-8859-1 encoded; or 2) modify server settings to declared UTF-8 for .js files or (less reliably) add charset=utf-8 attribute to the script element.

Alternatively, if the alert() invocation is really inside a script element in an HTML file, then perhaps this file is really UTF-8 encoded but you don’t observe other problems because the content of the file does not otherwise contain Icelandic characters. In this case, it is best to open the HTML file in your authoring program and change its encoding to windows-1252 or ISO-8859-1.

于 2012-06-21T14:33:47.977 回答