471,596 Members | 1,045 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

will the alerts displaying correctly?

How to make javascript alert with non-english text displaying correctly
on computers where english only is default system & language settings?
For web page the solution is just use meta tags:
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
Will this work for javascript alerts also?

Apr 3 '06 #1
12 2134
Any ideas?

Apr 3 '06 #2
ko****@hotmail.com wrote:
How to make javascript alert with non-english text displaying correctly
on computers where english only is default system & language settings?
For web page the solution is just use meta tags:
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
Will this work for javascript alerts also?


Maybe, maybe not. Windows-1251 ("Cyrillic") certainly includes characters
that are not part of the English language.[1] (The system and user
interface language do not matter.) But you SHOULD always send the correct
Content-Type HTTP header to declare the correct resource encoding (which
takes precedence over any meta[http-equiv]) to encode the used characters
of the HTML Document Character Set (UCS), and include meta[http-equiv] for
local use only.[2]

If that encoding does not allow to encode the character as-is, you can
either use character references (CRs) or character entity references (CERs)
_in the markup_, such as `Й', or change the encoding of the resource
content itself (and declare the new encoding instead). It is a common
misconception that the encoding of a markup resource would restrict you
to a certain character set. That is not the case; HTML 4.01 and XML
documents will use UCS as Document Character Set always.[3][4]

Note that CRs and CERs are not evaluated within JS strings, unless the piece
of JS code is CDATA _attribute_ content (or PCDATA _element_ content, what
you usually do not want).
PointedEars
___________
[1] <URL:http://en.wikipedia.org/wiki/Windows-1251>

[2] <URL:http://rfc-editor.org/rfc/rfc1945.txt>, 10.5
<URL:http://rfc-editor.org/rfc/rfc1945.txt>, 14.17

[3] <URL:http://www.w3.org/TR/html4/charset.html#doc-char-set>
<URL:http://www.w3.org/TR/html4/sgml/sgmldecl.html>

<URL:http://www.w3.org/TR/REC-xml/#charsets>
<URL:http://www.w3.org/TR/xml11#charsets>
<URL:http://www.w3.org/TR/NOTE-sgml-xml-971215.html#null3>

[4] Interestingly, HTML 3.2 documents use only ISO 646 (IA5) instead:
<URL:http://www.w3.org/TR/REC-html32#sgmldecl>
Apr 3 '06 #3

Thomas 'PointedEars' Lahn писал(а):
ko****@hotmail.com wrote:
How to make javascript alert with non-english text displaying correctly
on computers where english only is default system & language settings?
For web page the solution is just use meta tags:
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
Will this work for javascript alerts also?


Maybe, maybe not. Windows-1251 ("Cyrillic") certainly includes characters
that are not part of the English language.[1] (The system and user
interface language do not matter.) But you SHOULD always send the correct
Content-Type HTTP header to declare the correct resource encoding (which
takes precedence over any meta[http-equiv]) to encode the used characters
of the HTML Document Character Set (UCS), and include meta[http-equiv] for
local use only.[2]

If that encoding does not allow to encode the character as-is, you can
either use character references (CRs) or character entity references (CERs)
_in the markup_, such as `Й', or change the encoding of the resource
content itself (and declare the new encoding instead). It is a common
misconception that the encoding of a markup resource would restrict you
to a certain character set. That is not the case; HTML 4.01 and XML
documents will use UCS as Document Character Set always.[3][4]

Note that CRs and CERs are not evaluated within JS strings, unless the piece
of JS code is CDATA _attribute_ content (or PCDATA _element_ content, what
you usually do not want).
PointedEars
___________
[1] <URL:http://en.wikipedia.org/wiki/Windows-1251>

[2] <URL:http://rfc-editor.org/rfc/rfc1945.txt>, 10.5
<URL:http://rfc-editor.org/rfc/rfc1945.txt>, 14.17

[3] <URL:http://www.w3.org/TR/html4/charset.html#doc-char-set>
<URL:http://www.w3.org/TR/html4/sgml/sgmldecl.html>

<URL:http://www.w3.org/TR/REC-xml/#charsets>
<URL:http://www.w3.org/TR/xml11#charsets>
<URL:http://www.w3.org/TR/NOTE-sgml-xml-971215.html#null3>

[4] Interestingly, HTML 3.2 documents use only ISO 646 (IA5) instead:
<URL:http://www.w3.org/TR/REC-html32#sgmldecl>

----------

I've tested it and it worked OK for me. I just want to be sure that the
users will see correct text. I can rely on correct charset only.
Thanks for info.

Apr 3 '06 #4
ko****@hotmail.com wrote:
I've tested it and it worked OK for me.
That does not matter.
I just want to be sure that the users will see correct text.
They will see the correct text if the declared encoding and the actual
encoding of the resource match. The encoding declared in the HTTP header,
not in the `meta' element.
I can rely on correct charset only. Thanks for info.

^^^^^^^^^^^^^^^
You are welcome, but ISTM you have not understood yet.

Please trim your quotes next time.
<URL:http://www.safalra.com/special/googlegroupsreply/>
PointedEars
Apr 3 '06 #5

Thomas 'PointedEars' Lahn писал(а):
ko****@hotmail.com wrote:
I've tested it and it worked OK for me.
That does not matter.
I just want to be sure that the users will see correct text.


They will see the correct text if the declared encoding and the actual
encoding of the resource match. The encoding declared in the HTTP header,
not in the `meta' element.
I can rely on correct charset only. Thanks for info.

^^^^^^^^^^^^^^^
You are welcome, but ISTM you have not understood yet.

Please trim your quotes next time.
<URL:http://www.safalra.com/special/googlegroupsreply/>
PointedEars

--------------------
They will see the correct text if the declared encoding and the actual
encoding of the resource match. The encoding declared in the HTTP header,
not in the `meta' element.


not clear. How should look this 'right' encoding in html page? Its
better to show example with 'right' HTTP header and 'meta' element.

Apr 4 '06 #6
ko****@hotmail.com wrote:
Thomas 'PointedEars' Lahn писал(а):
[...]
> I can rely on correct charset only. Thanks for info. ^^^^^^^^^^^^^^^
You are welcome, but ISTM you have not understood yet.

Please trim your quotes next time.
<URL:http://www.safalra.com/special/googlegroupsreply/>
[...]

They will see the correct text if the declared encoding and the actual
encoding of the resource match. The encoding declared in the HTTP
header, not in the `meta' element.


not clear. How should look this 'right' encoding in html page?


It is the encoding used when storing the text content as a file.
Its better to show example with 'right' HTTP header and 'meta' element.
Try <URL:http://pointedears.de/scripts/test/cyrillic2>
(It has been a while since I have learned Russian, so please bear with me.)

This is the source code used:

<?php
if (isset($_GET['correct']))
{
header('Content-Type: text/html; charset=UTF-8');
}

// Demonstrates what the wrong default encoding can do to a resource
else
{
header('Content-Type: text/html; charset=Windows-1251');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scripting Test Case: Encoding vs. Document Character Set</title>

<meta name="DCTERMS.created" content="2006-04-04">

<script type="text/javascript">
function foo()
{
alert("Понимаешь?");
}
</script>

<style type="text/css">
body {
background-color: white;
color: black;
}

div, p {
margin: 1em auto;
}

acronym {
border-bottom:1px dotted #999;
cursor: help;
}
</style>
</head>

<body>
<?php
if (!isset($_GET['correct']))
{
?>
<p>This <a href="http://en.wikipedia.org/wiki/UTF-8"><acronym
title="8-bit Unicode Transformation Format">UTF-8</acronym></a>
encoded resource is served with the wrong encoding declaration in
the <tt>Content-Type</tt> <a
href="http://en.wikipedia.org/wiki/HyperText_Transfer_Protocol"<acronym title="HyperText Transfer Protocol"
HTTP</acronym></a>&nbsp;header (<tt>charset=<a href="http://en.wikipedia.org/wiki/Windows-1251"Windows-1251</a></tt>). That the included <a href="http://www.w3.org/TR/html4/struct/global.html#edef-META"<tt>meta</tt></a> element "declares" the correct encoding does not matter; the HTTP&nbsp;header takes precedence.</p>

<p>Nevertheless, the <a
href="http://www.w3.org/TR/html4/charset.html#h-5.1"Document Character Set for <acronym title="HyperText Markup Language">HTML</acronym>&nbsp;4.01
documents</a> is still <a
href="http://en.wikipedia.org/wiki/Universal_Character_Set"<acronym title="the Universal Character Set">UCS</acronym></a>, so character references can be used in <a
href="http://en.wikipedia.org/wiki/CDATA"><tt>CDATA</tt></a>
attribute values to represent non-<a
href="http://en.wikipedia.org/wiki/ASCII"><acronym
title="American Standard Code for Information Interchange"ASCII</acronym></a> characters:</p> <?php
}
?>

<div><input type="button"
value="Выбери
меня!"
lang="ru"
onclick="foo();"></div>

<?php
if (!isset($_GET['correct']))
{
?>
<div><a href="?correct=1"Serve (almost) the same content with the correct encoding

declaration
(<tt>charset=UTF-8</tt>)</a></div>
<?php
}
?>
</body>
</html>
HTH

PointedEars

P.S.
I asked you to trim your quotes already (reduce it to the minimum necessary
to retain context, as you can observe in [my] other postings).
Apr 4 '06 #7
> ko****@hotmail.com wrote:
Thomas 'PointedEars' Lahn писал(а):
[...]
> I can rely on correct charset only. Thanks for info.
^^^^^^^^^^^^^^^
You are welcome, but ISTM you have not understood yet.

Please trim your quotes next time. http://www.safalra.com/special/googlegroupsreply/> [...]

They will see the correct text if the declared encoding and the actual
encoding of the resource match. The encoding declared in the HTTP
header, not in the `meta' element.


not clear. How should look this 'right' encoding in html page?


It is the encoding used when storing the text content as a file.
Its better to show example with 'right' HTTP header and 'meta' element.


Try <URL:http://pointedears.de/scripts/test/cyrillic2>
(It has been a while since I have learned Russian, so please bear with me..)

This is the source code used:

<?php
if (isset($_GET['correct']))
{
header('Content-Type: text/html; charset=UTF-8');
}

// Demonstrates what the wrong default encoding can do to a resource
else
{
header('Content-Type: text/html; charset=Windows-1251');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scripting Test Case: Encoding vs. Document Character Set</title>

<meta name="DCTERMS.created" content="2006-04-04">

<script type="text/javascript">
function foo()
{
alert("Понимаешь?");
}
</script>

<style type="text/css">
body {
background-color: white;
color: black;
}

div, p {
margin: 1em auto;
}

acronym {
border-bottom:1px dotted #999;
cursor: help;
}
</style>
</head>

<body>
<?php
if (!isset($_GET['correct']))
{
?>
<p>This <a href="http://en.wikipedia.org/wiki/UTF-8"><acronym
title="8-bit Unicode Transformation Format">UTF-8</acronym></a>
encoded resource is served with the wrong encoding declaration in
the <tt>Content-Type</tt> <a
href="http://en.wikipedia.org/wiki/HyperText_Transfer_Protocol"
><acronym title="HyperText Transfer Protocol"
>HTTP</acronym></a>&nbsp;header (<tt>charset=<a

href="http://en.wikipedia.org/wiki/Windows-1251"
>Windows-1251</a></tt>). That the included <a

href="http://www.w3.org/TR/html4/struct/global.html#edef-META"
><tt>meta</tt></a> element "declares" the correct encoding does

not matter; the HTTP&nbsp;header takes precedence.</p>

<p>Nevertheless, the <a
href="http://www.w3.org/TR/html4/charset.html#h-5.1"
>Document Character Set for <acronym

title="HyperText Markup Language">HTML</acronym>&nbsp;4.01
documents</a> is still <a
href="http://en.wikipedia.org/wiki/Universal_Character_Set"
><acronym title="the Universal Character Set">UCS</acronym></a>,

so character references can be used in <a
href="http://en.wikipedia.org/wiki/CDATA"><tt>CDATA</tt></a>
attribute values to represent non-<a
href="http://en.wikipedia.org/wiki/ASCII"><acronym
title="American Standard Code for Information Interchange"
>ASCII</acronym></a> characters:</p>

<?php
}
?>

<div><input type="button"
value="Выбери
меня!"
lang="ru"
onclick="foo();"></div>

<?php
if (!isset($_GET['correct']))
{
?>
<div><a href="?correct=1"
>Serve (almost) the same content with the correct encoding

declaration
(<tt>charset=UTF-8</tt>)</a></div>
<?php
}
?>
</body>
</html>
HTH

PointedEars

P.S.
I asked you to trim your quotes already (reduce it to the minimum necessary
to retain context, as you can observe in [my] other postings).

----------------------

this one show wrong text:

http://pointedears.de/scripts/test/cyrillic2 show wrong text,
this -correct:
http://pointedears.de/scripts/test/cyrillic2?correct=1

but both pages have same doctype & meta tags, I dont understand what is
difference:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scripting Test Case: Encoding vs. Document Character
Set</title>

<meta name="DCTERMS.created" content="2006-04-04">

AND

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scripting Test Case: Encoding vs. Document Character
Set</title>

<meta name="DCTERMS.created" content="2006-04-04">
Button value in both pages shown unreadable:

<div><input type="button"
value="Выбери
меня!"
lang="ru"
onclick="foo();"></div>

Apr 4 '06 #8
ko****@hotmail.com wrote:
ko****@hotmail.com wrote:
[...]
> Thomas 'PointedEars' Lahn писал(а):
>> [...] P.S.
I asked you to trim your quotes already (reduce it to the minimum
necessary to retain context, as you can observe in [my] other postings).

----------------------

this one show wrong text:

http://pointedears.de/scripts/test/cyrillic2 show wrong text,

this -correct:
http://pointedears.de/scripts/test/cyrillic2?correct=1


Works as designed :)
but both pages have same doctype & meta tags,
As I said (and wrote), the `meta' element does not matter really.
I dont understand what is difference:
I thought the text to be self-explanatory, with that many links in it ...
FWIW:

Compare the displayed response headers and document content with

<URL:http://web-sniffer.net/?url=http%3A%2F%2Fpointedears.de%2Fscripts%2Ftest% 2Fcyrillic2&submit=Submit&http=1.1&rawhtml=no&gzip =yes&type=GET&ua=Mozilla%2F5.0+%28X11%3B+U%3B+Linu x+i686%3B+en-US%3B+rv%3A1.8.0.1%29+Gecko%2F20060313+Debian%2F1. 5.dfsg%2B1.5.0.1-4+Firefox%2F1.5.0.1+Web-Sniffer%2F1.0.24>
(without ?correct=1, causing PHP to generate the wrong header value)

and

<URL:http://web-sniffer.net/?url=http%3A%2F%2Fpointedears.de%2Fscripts%2Ftest% 2Fcyrillic2%3Fcorrect%3D1&submit=Submit&http=1.1&r awhtml=no&gzip=yes&type=GET&ua=Mozilla%2F5.0+%28X1 1%3B+U%3B+Linux+i686%3B+en-US%3B+rv%3A1.8.0.1%29+Gecko%2F20060313+Debian%2F1. 5.dfsg%2B1.5.0.1-4+Firefox%2F1.5.0.1+Web-Sniffer%2F1.0.24>
(with ?correct=1, causing PHP to generate the correct header value)
[...]
Button value in both pages shown unreadable:


The button value (its caption) should show the _same_ (cyrillic) letters
with both declarations, or either your browser is broken or you do not have
the correct Unicode font installed (or configured). However, the alert()
message box displayed when the button is clicked should be _different_ (and
you wrote that it was), or your browser is broken.

Next time you do not trim your quotes as recommended, I will stop reading
your postings. I have given you enough hints now.
PointedEars
Apr 4 '06 #9
> I thought the text to be self-explanatory, with that many links in it ...
FWIW: Compare the displayed response headers and document content with http://web-sniffer.net/?url=http%3A%...iffer%2F1.0.24
(without ?correct=1, causing PHP to generate the wrong header value) and http://web-sniffer.net/?url=http%3A%...iffer%2F1.0.24
(with ?correct=1, causing PHP to generate the correct header value)
Button value in both pages shown unreadable:

The button value (its caption) should show the _same_ (cyrillic) letters
with both declarations, or either your browser is broken or you do not have
the correct Unicode font installed (or configured). However, the alert()
message box displayed when the button is clicked should be _different_ (and
you wrote that it was), or your browser is broken. Next time you do not trim your quotes as recommended, I will stop reading
your postings. I have given you enough hints now. PointedEars

-----------------
this Google Groups has extremelly inconvenient plain user interface so
I really problematic trim someting there
Your examples imply the use of php, while I meant using just plain html
pages. And button value is broken for me in both cases. Dont know what
about browser, i still use MSIE, though its bad, however
As to correct Unicode font installed -i have default configuratuon,
usually no problem to read anything.

Apr 4 '06 #10
ko****@hotmail.com wrote:
> Button value in both pages shown unreadable:
The button value (its caption) should show the _same_ (cyrillic) letters
with both declarations, or either your browser is broken or you do not
have the correct Unicode font installed (or configured). However, the
alert() message box displayed when the button is clicked should be
_different_ (and you wrote that it was), or your browser is broken.

Next time you do not trim your quotes as recommended, I will stop reading
your postings. I have given you enough hints now.

[...]
this Google Groups has extremelly inconvenient [...] user interface


True. Use Google Groups only for research, not for posting.
so I really problematic trim someting there
No, it is not :)

<URL:http://www.safalra.com/special/googlegroupsreply/>
<URL:http://netmeister.org/news/learn2quote.html>
<URL:http://jibbering.com/faq/faq_notes/pots1.html>

(Especially, signatures should not be quoted, unless there is an explicit
reference in the followup.)
Your examples imply the use of php, while I meant using just plain html
pages.
PHP was only used to simulate the server sending a default encoding that
does not match the actual encoding of the resource. What happens is
that the `meta' element is ignored then, which is correct behavior.[1]
Therefore, the UTF-8 encoded Cyrillic characters look garbled then.

[1] Another example:
<URL:http://issues.apache.org/bugzilla/show_bug.cgi?id=23421>
(The reporter's name is "Martin Dürst", stored UTF-8 encoded;
the document contains meta[content="text/html; charset=UTF-8"],
but is incorrectly served as charset=ISO-8859-1 in the
Content-Type HTTP header.)
And button value is broken for me in both cases. Dont know what
about browser, i still use MSIE, though its bad, however
Define: broken. (URL for screenshot?)
As to correct Unicode font installed -i have default configuratuon,
usually no problem to read anything.


Straynge. [psf 4.15]
PointedEars
Apr 4 '06 #11
Thomas 'PointedEars' Lahn wrote:
ko****@hotmail.com wrote:
[...]
[1] Another example:
<URL:http://issues.apache.org/bugzilla/show_bug.cgi?id=23421>
(The reporter's name is "Martin Dürst", stored UTF-8 encoded;
the document contains meta[content="text/html; charset=UTF-8"],
Hm, it does not contain a `meta' element. Maybe that makes the
difference for your IE. That would be against the HTTP standard,
so nothing that should be relied upon, though.
but is incorrectly served as charset=ISO-8859-1 in the
Content-Type HTTP header.)
And button value is broken for me in both cases. Dont know what
about browser, i still use MSIE, though its bad, however

[...]

PointedEars
Apr 4 '06 #12
Thomas 'PointedEars' Lahn said the following on 4/4/2006 2:42 PM:

<snip>
(Especially, signatures should not be quoted, unless there is an explicit
reference in the followup.)
<snip>
Straynge. [psf 4.15]
PointedEars


Where is the "signature" that should not be quoted? If you want to
continue to rant about people quoting a "signature" that is *NOT* a
signature, then start using a proper signature. Otherwise, shut up with
your pedantic ramblings about such things.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 4 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ryan baldwin | last post: by
1 post views Thread by rhompi | last post: by
2 posts views Thread by Luis Esteban Valencia | last post: by
7 posts views Thread by swethasivaram | last post: by
reply views Thread by Andy Lim | last post: by
1 post views Thread by =?Utf-8?B?R2VvcmdlIFIu?= | last post: by
4 posts views Thread by redpears007 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.