2

i have an alert box which i want to show some icelandic text but its not showing it

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

it is showing the alert box but the text is messed up :(

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

any help please :(

baig772
  • 3,404
  • 11
  • 48
  • 93

4 Answers4

6

Today the web uses many international languages and has settled on using UTF-8 (a flavour of unicode) for character encoding. This is important.

You are using iso-8859-1, the MS Windows character set. If you have Word 2007 or 2010 you have the option of re-saving your text as UTF-8. If you've ever seen ????? or instead of text on someone's web site, it's due to the wrong encoding type.

<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>

Always use UTF-8 end-to end. Do not use 8859-1 or Windows 2151 encoding.

See:

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

ISO-8859-1 vs UTF-8?

Character encodings and the beauty of UTF-8

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • i did this but now alert is ok but my other icelandic text is now messed up :( – baig772 Jun 21 '12 at 13:35
  • You need to use UTF-8 end-to-end or you will continue to have these encoding problems. It may be painful to go back and fix this, but for the sake of standards and compatibility IT MUST BE DONE. – Diodeus - James MacFarlane Jun 21 '12 at 13:44
  • thanks man. now it is solved :) but its ahard job to do. next time i will definately not do such blunder :) – baig772 Jun 21 '12 at 13:46
2

Let's do it in html5 manner :)

<!doctype html>
<html>
   <head>
       <meta charset = "utf-8" />
   </head>
madeye
  • 1,398
  • 3
  • 15
  • 33
  • tried it but now alert is ok and other icelandic text is messed up. cannot risk whole site for one alert :( – baig772 Jun 21 '12 at 13:40
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
Stephan Hepper
  • 420
  • 4
  • 6
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.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390