HTML5 <meta> tag's attributes effects on older browsers

别说谁变了你拦得住时间么 提交于 2019-12-25 02:41:13

问题


My markup has the simple HTML5 compatible <meta> tag like so:

<meta charset="UTF-8">

The document validates well under the HTML5 doctype, but what disadvantages, if any, are there to using this method when it comes to older browsers?

While IE8 and below make up a small percentage of the market share, they do still exist out in the wild, especially in corporate environments. I am finding myself lately producing sites for these corporate environments more and more often and am curious as to what the correct procedure is for backwards compatibility. SEO is generally not a high priority as these are mostly "internal use only" sites that I am working with.

What are the pros and cons of using

<meta charset="UTF-8">

over

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

and vice-versa?


回答1:


There are no known disadvantages. I just tested with IE 6 (in a virtual XP machine), and it manages <meta charset=utf-8> fine. And you can hardly find an older browser than that in the wild these days.

This is not surprising, since the construct was added to HTML5 after observing how browsers actually parse HTML. This is described in section Extracting character encodings from meta elements in HTML5 CR. The browsers effectively just searches for charset= in the tag and then reads the encoding name after that string. This means that e.g. <meta sdvhnizfb vjkfhifgb ¤¤#%#charset="utf-8"> works, too, though it not particularly recommendable.

The advantages of <meta charset=utf-8> are simplicity, conciseness, and intuitive understandability. And when typing a short string like that, you will seldom make mistakes like you might do with a more complicated string. Just like <!doctype html> is finally a doctype that you can easily memorize, <meta charset=utf-8> can easily be learned and typed. Of course, you should normally use document templates or similar tools, but the point is that you can type those constructs when needed, without consulting a manual.



来源:https://stackoverflow.com/questions/20361693/html5-meta-tags-attributes-effects-on-older-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!