当我们没有指定< meta charset =" utf-8"&gt ;?时会发生什么? [英] What happens when we don't specify <meta charset="utf-8">?

查看:347
本文介绍了当我们没有指定< meta charset =" utf-8"&gt ;?时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们没有指定< meta charset =utf-8> 时会发生什么?在HTML文档的HEAD中?

解决方案

无论这样的 meta 标记是否存在,浏览器和用户代理将首先查看HTTP标题以在其中查找编码信息。实际上,他们甚至会在兑现用户设置和进行BOM嗅探之前,如第8.2.2.1节,这是本期对现实的描述,而不仅仅是建议的标准。所以答案是这样的真的取决于。在许多情况下, meta 标签被忽略,所以忽略它不起作用,除非在HTML文档保存在本地的情况下(这样HTTP标头丢失)。在许多其他情况下,它不会被忽略,但如果省略,浏览器无论如何都会推断正确的编码。在某些情况下,标签恰好是使浏览器使用正确编码的唯一因素,忽略它会导致数据的错误解释,通常这会导致在Windows-1252编码中解释字节。这很重要取决于实际内容。


What happens when we don't specify <meta charset="utf-8"> ? in the HEAD of the HTML document?

解决方案

Whether such a meta tag is present or not, browsers and user agents will first look at the HTTP headers to find encoding information there. Actually, they will even before that honor user settings and do BOM sniffing, as described in section 8.2.2.1 Determining the character encoding in HTML5 CR – which is in this issue a description of the reality rather than just proposed norm.

So the answer is really "it depends". In many cases, the meta tag is ignored, so omitting it has no effect, except perhaps in situations where the HTML document is saved locally (so that HTTP headers are lost). In many other cases, it is not ignored, but if it is omitted, browsers will infer the correct encoding anyway. And in some cases, where the tag happens to be the only thing that makes the browser use the right encoding, omitting it will cause wrong interpretation of data, typically so that bytes are interpreted in windows-1252 encoding. What this matters depends on the actual content.

这篇关于当我们没有指定&lt; meta charset =&quot; utf-8&quot;&gt ;?时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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