为什么我们需要HTML头中的元内容类型标签? [英] Why do we need the meta content type tag in HTML head?

查看:136
本文介绍了为什么我们需要HTML头中的元内容类型标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要像这样在HTML头中包含元内容类型标签?

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


解决方案

每当网页在本地打开时系统)中,文本/ html 部分将指示webbrowser文档的类型,以便它知道如何解析它以及 charset = UTF -8 将指示网页浏览器应使用哪种字符编码来显示网页上的字符,以便它不会使用平台默认编码(这可能不是正确的,因此可能潜在地最终成为 mojibake )。

重要的细节是,当通过HTTP在网络上提供页面时,不会使用此HTML元标头。相反,将使用HTTP响应头中的 Content-Type 一个。因此,如果这个文件缺少 charset = UTF-8 部分,而内容实际上被解码为UTF-8,那么它很可能会变成mojibake。您可以使用例如 Firebug 来确定 Content-Type 标题 Net 面板。




Why do we need to include the meta content type tag in HTML head like this?

<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).

Important detail is that this HTML meta header isn't been used when the page is served over the web by HTTP. Instead, the Content-Type one in the HTTP response header will be used. So if this lacks the charset=UTF-8 part while the content is actually decoded as UTF-8, then it will likely go mojibake. You can determine the Content-Type header with for example Firebug, in the Net panel.

这篇关于为什么我们需要HTML头中的元内容类型标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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