(HTML 5.2)按照以下优先级顺序进行,其中BOM优先级最高:
1.BOM
2.ContentType中指定的charset
3.html文档中meta元素指定的charset
BOM(Byte order mark)
如果文本流开始时出现了BOM并指定了使用哪种Unicode编码,则浏览器应使用指定的Unicode编码解码文本流
ContentType
如果没有BOM,则应按照服务器发送的HTTP响应头部中ContentType指定的charset来解码
meta charset
如果没有BOM,HTTP响应头部中ContentType也未指定charset,浏览器会使用使用它默认的字符编码来解码(一般是ISO-8859-1)
这个时候如果遇到了meta元素指定了charset,则整个文档应重新按照所指定的来进行解码
参考:
<meta charset=“utf-8”> declares encoding of own file?
What is the difference between the charset in http header and html meta?
HTML 5.2 8.2.2.2. Determining the character encoding
HTML 5.2 4.2.5.5. Specifying the document’s character encoding
网友评论