使用Windows-1252编码的HTML5文档的验证错误

发布于 2025-02-07 02:52:15 字数 656 浏览 1 评论 0原文

w3.org html验证器 https://validator.w3.org 出乎意料地显示出Html5文档的错误使用编码ISO-8859-1。

消息是:

错误旧编码Windows-1252所使用的旧版。文档必须使用UTF-8。

我发现许多资源仅表示UTF-8是推荐的编码。 我错过了什么,还是W3验证器错误消息值得怀疑?


例子:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Untitled document</title>
  </head>
  <body>
    <p>
       à la mode 
    </p>
  </body>
</html>

The w3.org HTML validator https://validator.w3.org unexpectedly shows an error for a HTML5 document which uses the encoding iso-8859-1.

The message is:

Error Legacy encoding windows-1252 used. Documents must use UTF-8.

I found many resources which only indicate UTF-8 being the recommended encoding.
Did I miss something, or is the w3 validator error message questionable?


Example:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Untitled document</title>
  </head>
  <body>
    <p>
       à la mode 
    </p>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意犹 2025-02-14 02:52:15

在HTML5中,要指定文档的charset,您应该使用较新的&lt; meta charset =“ ...”&gt;,而不是较旧的&lt; meta http-equiv =“ content-键入“ content =” text/html

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="windows-1252">
    <title>Untitled document</title>
  </head>
  <body>
    <p>
       à la mode 
    </p>
  </body>
</html>

;

4.2.5.4指定文档的字符编码

字符编码声明是一种机制,通过该机制指定了用于存储或发送文档的字符编码。

编码标准需要使用UTF-8字符编码,并且需要使用“ UTF-8”编码标签来识别它。这些要求需要文档的字符编码声明,如果存在,使用“ UTF-8”的ASCII案例不敏感的匹配指定编码标签。不管是否存在编码声明的字符,用于编码文档的实际字符必须为UTF-8

也:

编码声明状态(http-equiv =“ content-type”)

编码声明状态只是设置charset属性的另一种形式:它是一个字符编码声明。该州的用户代理要求均由规范的解析部分处理。

对于具有http-equiv属性的元元素,在编码声明状态中,内容属性必须具有一个值的值,该值是ASCII案例不敏感的匹配,该字符串包含:文字字符串“ text/html;”,html;可选地进行任意数量的ASCII Whitespace,然后是字面字符串“ charset = utf-8”

这意味着验证器是正确的。您不允许您在现代HTML中使用Windows-1252/ISO-8859-1(或任何其他CharSet),仅在UTF-8中。这不仅是建议,而且是一项要求。

特定的Web浏览器是否选择执行 此要求是另一回事

In HTML5, to specify the document's charset, you should use the newer <meta charset="..."> instead of the older <meta http-equiv="Content-Type" content="text/html; charset=..."> (which is still supported for legacy reasons), eg:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="windows-1252">
    <title>Untitled document</title>
  </head>
  <body>
    <p>
       à la mode 
    </p>
  </body>
</html>

But, that being said, the current HTML5 standard states:

4.2.5.4 Specifying the document's character encoding

A character encoding declaration is a mechanism by which the character encoding used to store or transmit a document is specified.

The Encoding standard requires use of the UTF-8 character encoding and requires use of the "utf-8" encoding label to identify it. Those requirements necessitate that the document's character encoding declaration, if it exists, specifies an encoding label using an ASCII case-insensitive match for "utf-8". Regardless of whether a character encoding declaration is present or not, the actual character encoding used to encode the document must be UTF-8.

As well as:

Encoding declaration state (http-equiv="content-type")

The Encoding declaration state is just an alternative form of setting the charset attribute: it is a character encoding declaration. This state's user agent requirements are all handled by the parsing section of the specification.

For meta elements with an http-equiv attribute in the Encoding declaration state, the content attribute must have a value that is an ASCII case-insensitive match for a string that consists of: the literal string "text/html;", optionally followed by any number of ASCII whitespace, followed by the literal string "charset=utf-8".

Which means, the validator is correct. You are not allowed to use Windows-1252/ISO-8859-1 (or any other charset) anymore in modern HTML, only UTF-8. It is not just a recommendation, it is a requirement.

Whether or not particular web browsers choose to enforce this requirement is another matter, though...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文