简体   繁体   English

为什么我们需要HTML头中的元内容类型标记?

[英]Why do we need the meta content type tag in HTML head?

Why do we need to include the meta content type tag in HTML head like this? 为什么我们需要像这样在HTML头中包含元内容类型标记?

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

Whenever the webpage is been opened locally (from disk file system), the text/html part will instruct the webbrowser of which type the document is so that it knows how to parse it and the charset=UTF-8 will instruct the webbrowser which character encoding should be used to display the characters on the webpage so that it won't use the platform default encoding (which may not necessarily be the right one which would thus potentially end up as mojibake ). 每当在本地打开网页(从磁盘文件系统)时, text/html部分将指示webbrowser文件的类型,以便它知道如何解析它,而charset=UTF-8将指示webbrowser哪个字符编码应该用于显示网页上的字符,以便它不会使用平台默认编码(可能不一定是正确的编码因此可能最终成为mojibake )。

Important detail is that this HTML meta header isn't been used when the page is served over the web by HTTP. 重要的细节是,当通过HTTP在Web上提供页面时,未使用此HTML元标头。 Instead, the Content-Type one in the HTTP response header will be used. 而是使用HTTP响应头中的Content-Type 1。 So if this lacks the charset=UTF-8 part while the content is actually decoded as UTF-8, then it will likely go mojibake. 因此,如果缺少charset=UTF-8部分,而内容实际上被解码为UTF-8,那么它可能会变成mojibake。 You can determine the Content-Type header with for example Firebug , in the Net panel. 您可以在Net面板中使用Firebug确定Content-Type标头。

替代文字

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata. 元元素通常用于指定页面描述,关键字,文档的作者,最后修改的元数据和其他元数据。

The meta tag you have posted, will instruct the browser to have text/html type of document with character set or language set to UTF-8 . 您发布的元标记将指示浏览器具有text/html类型的文档,其中字符集或语言设置为UTF-8

Used to declare the character set. 用于声明字符集。

The Meta Content Type tag is used to declare the character set of a website. Meta Content Type标签用于声明网站的字符集。 It has become recommended to always use the Meta Content Type tag even if you use a DTD declaration above the Header. 即使您在标题上方使用DTD声明,也建议始终使用Meta Content Type标记。 If you fail to do so, it may cause display problems. 如果您没有这样做,可能会导致显示问题。 For instance, the document may use UTF-8 punctuation characters but is displayed in ISO or ASCII character sets. 例如,文档可能使用UTF-8标点字符,但以ISO或ASCII字符集显示。 There are other benefits to using the Meta Content Type tag. 使用Meta Content Type标记还有其他好处。 Simply subscribe to our SEO Revolution Newsletter (nominal fee membership) to get the entire scoop of what the Meta Content Type tag can do for your site 只需订阅我们的SEO革命新闻通讯(象征性费用会员)即可获得Meta Content Type标签可为您的网站做的全部内容

See this for more info: 有关详细信息,请参阅此

这样浏览器就会知道如何解码页面 - 例如:根据语言的不同,最终结果可能会有很大不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM