http标头中的字符集和html meta有什么区别? [英] What is the difference between the charset in http header and html meta?

查看:87
本文介绍了http标头中的字符集和html meta有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在http响应标头中发送字符集,也可以在已发送的html文件中定义字符集。

You can send the charset both in the http response headers and also you can define a charset in the html file you have sent..

如果这两个字符会发生什么是不同的字符集?浏览器如何将字符集用于在HTTP标头中收到的字符集,以及在html文件本身中提供的字符集有什么关系呢?

What happens if these 2 are different charsets? How does the browser use the charset for what it received in the http headers and where does it matter what charset it provided in the html file itself?

推荐答案

HTML 4.01规范在5.2.2中明确指出指定字符编码,即HTTP标头中的信息优先于标记。 HTML5 PR不会对此进行更改,但会在8.2.2.2 确定字符编码,以确保它们都被HTML文档开头的字节顺序标记(BOM)覆盖(因此,如果您将.html文件保存为另存为UTF, -8(带有BOM),则无论如何都将被视为UTF-8。)

The HTML 4.01 specification clearly says, in 5.2.2 Specifying the character encoding, that information in an HTTP header has precedence over a meta tag. HTML5 PR does not change this, but it adds, reflecting browser practice, in 8.2.2.2 Determining the character encoding that both of them are overridden by a Byte Order Mark (BOM) at the start of the HTML document (so if you have saved your .html file with "Save as UTF-8 with BOM", it will be treated as UTF-8 no matter what).

A 标签如果未在HTTP标头或BOM表中提供该信息,则指定字符编码的设置将生效。服务器可能在 Content-Type 标头中不包含 charset 参数,或者可能会在本地打开HTML文档,以便根本没有HTTP标头。用户将HTML文档保存在自己的设备中时,不会保存HTTP标头。这是使用 meta 标签指定字符编码的主要原因。但是它随后应该指定正确的编码。

A meta tag that specifies character encoding takes effect if the information is not provided in an HTTP header or with a BOM. A server might not include charset parameter in the Content-Type header, or the HTML document might be opened locally so that there are no HTTP headers at all. When a user saves an HTML document in his own device, the HTTP headers are not saved. This is the main reason for using a meta tag to specify character encoding; but it should then specify the correct encoding of course.

这篇关于http标头中的字符集和html meta有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆