Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

html - What happens when we don't specify <meta charset="utf-8">?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...