meta元素有4个属性:name、http-equiv、content、charset.meta标签通过name属性来表述页面文档的元信息,通过http-equiv属性设置http请求指令,通过charset设置页面的字符编码。按照属性设置分类,meta可以分为三类: name属性和content属 ......
meta元素有4个属性:name、http-equiv、content、charset.meta标签通过name属性来表述页面文档的元信息,通过http-equiv属性设置http请求指令,通过charset设置页面的字符编码。按照属性设置分类,meta可以分为三类:
-
name属性和content属性组合,构成名称/值对,用于描述网站信息.
标准的meta名称包括application-name、author、description、generator等。
示例代码:
<meta name="keywords" content="british,typeface,font,fonts"/>
其中keywords和description这两个名称的使用率最高,是搜索引擎优化的主要手段之一,推荐读者使用。
-
http-equiv属性和content属性组合,设置特定的http指令;
其中content-type、default-style和refresh已经确定,content-language和set-cookie还未正式确定.
此类型meta应该谨慎使用。不推荐使用<meta http-equiv="refresh" content="300"/>,某些搜索引擎遇到此meta时会停止解析 页面剩余的部分。<meta http-equiv="default-style">在实际的场景中很少使用
-
charset属性,设置页面字符编码。
此属性提供了保存和传输文档的编码格式。
<meta charset="utf-8">
等价于
<meta http-equiv='content-type' content='type=text/html; charset=utf-8'>
但是第一种形式更简洁好记,并且得到了所有主流浏览器的支持,所有不存在浏览器兼容问题。为 了让浏览器能准确识别编码格式,务必在<title>标签之前设置charset,保证标题能正确显示。
除了w3c定义的规范中定义的这些meta之外,还有大量的自定义meta类型。这些meta类型主要是由互联网公司或者浏览器厂商为了实现特定的功能而定制的。这些自定义的meta不能通过w3c提供的标准校验,但并不是说这些meta不标准。介绍一些常用的meta
设置ie浏览器的兼容模式
从ie8浏览器开始支持一种设置页面兼容模式的meta类型,示例代码如下:
<meta http-equiv="x-ua-compatible" content="ie=8"/>
根据html规范,浏览器是按照页面开头定义的文档类型来解析页面的。例如,使用html5的文档类型声明:
<!doctype html>
ie就会以标准模式解析html文档。但是某些已有页面由于各种原因不能在最新标准模式下正确显示,只支持特定的标准。针对这种情况,ie浏览器提供了一种兼容的方案,通过设置x-ua-compatible指定页面在ie浏览器中渲染时执行的标准。
此外还有一种很常见的设置值,即:
<meta http-equiv="x-ua-compatible" content="chrome=1"/>
ie定义的meta为什么会出现chrome呢?其实设置为chrome=1时,则会在ie9及以下浏览器中激活chrome frame,强制ie使用chrome frame渲染页面。
%0a%0a%23%23%23%23%23%20%26emsp%3b%26emsp%3b%20meta%e5%85%83%e7%b4%a0%e6%9c%894%e4%b8%aa%e5%b1%9e%e6%80%a7%ef%bc%9aname%e3%80%81http-equiv%e3%80%81content%e3%80%81charset.meta%e6%a0%87%e7%ad%be%e9%80%9a%e8%bf%87name%e5%b1%9e%e6%80%a7%e6%9d%a5%e8%a1%a8%e8%bf%b0%e9%a1%b5%e9%9d%a2%e6%96%87%e6%a1%a3%e7%9a%84%e5%85%83%e4%bf%a1%e6%81%af%ef%bc%8c%e9%80%9a%e8%bf%87http-equiv%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%aehttp%e8%af%b7%e6%b1%82%e6%8c%87%e4%bb%a4%ef%bc%8c%e9%80%9a%e8%bf%87charset%e8%ae%be%e7%bd%ae%e9%a1%b5%e9%9d%a2%e7%9a%84%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81%e3%80%82%e6%8c%89%e7%85%a7%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%ae%e5%88%86%e7%b1%bb%ef%bc%8cmeta%e5%8f%af%e4%bb%a5%e5%88%86%e4%b8%ba%e4%b8%89%e7%b1%bb%3a%0a%0a%0a*%20**name%e5%b1%9e%e6%80%a7%e5%92%8ccontent%e5%b1%9e%e6%80%a7%e7%bb%84%e5%90%88%2c%e6%9e%84%e6%88%90%e5%90%8d%e7%a7%b0%2f%e5%80%bc%e5%af%b9%ef%bc%8c%e7%94%a8%e4%ba%8e%e6%8f%8f%e8%bf%b0%e7%bd%91%e7%ab%99%e4%bf%a1%e6%81%af.**%0a%0a%20%20%20%20%20%26emsp%3b%26emsp%3b%20%e6%a0%87%e5%87%86%e7%9a%84meta%e5%90%8d%e7%a7%b0%e5%8c%85%e6%8b%acapplication-name%e3%80%81author%e3%80%81description%e3%80%81generator%e7%ad%89%e3%80%82%0a%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81%ef%bc%9a%0a%3cmeta%20name%3d%22keywords%22%20content%3d%22british%2ctypeface%2cfont%2cfonts%22%2f%3e%0a%0a%20%20%20%e5%85%b6%e4%b8%adkeywords%e5%92%8cdescription%e8%bf%99%e4%b8%a4%e4%b8%aa%e5%90%8d%e7%a7%b0%e7%9a%84%e4%bd%bf%e7%94%a8%e7%8e%87%e6%9c%80%e9%ab%98%ef%bc%8c%e6%98%af%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e4%bc%98%e5%8c%96%e7%9a%84%e4%b8%bb%e8%a6%81%e6%89%8b%e6%ae%b5%e4%b9%8b%e4%b8%80%ef%bc%8c%e6%8e%a8%e8%8d%90%e8%af%bb%e8%80%85%e4%bd%bf%e7%94%a8%e3%80%82%0a%0a*%20%20%20%20**http-equiv%e5%b1%9e%e6%80%a7%e5%92%8ccontent%e5%b1%9e%e6%80%a7%e7%bb%84%e5%90%88%ef%bc%8c%e8%ae%be%e7%bd%ae%e7%89%b9%e5%ae%9a%e7%9a%84http%e6%8c%87%e4%bb%a4%3b**%0a%20%20%20%26emsp%3b%e5%85%b6%e4%b8%adcontent-type%e3%80%81default-style%e5%92%8crefresh%e5%b7%b2%e7%bb%8f%e7%a1%ae%e5%ae%9a%2ccontent-language%e5%92%8cset-cookie%e8%bf%98%e6%9c%aa%e6%ad%a3%e5%bc%8f%e7%a1%ae%e5%ae%9a.%0a%20%20%20%e6%ad%a4%e7%b1%bb%e5%9e%8bmeta%e5%ba%94%e8%af%a5%e8%b0%a8%e6%85%8e%e4%bd%bf%e7%94%a8%e3%80%82%e4%b8%8d%e6%8e%a8%e8%8d%90%e4%bd%bf%e7%94%a8%3cmeta%20http-equiv%3d%22refresh%22%20content%3d%22300%22%2f%3e%2c%e6%9f%90%e4%ba%9b%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e9%81%87%e5%88%b0%e6%ad%a4meta%e6%97%b6%e4%bc%9a%e5%81%9c%e6%ad%a2%e8%a7%a3%e6%9e%90%20%e9%a1%b5%e9%9d%a2%e5%89%a9%e4%bd%99%e7%9a%84%e9%83%a8%e5%88%86%e3%80%82%3cmeta%20http-equiv%3d%22default-style%22%3e%e5%9c%a8%e5%ae%9e%e9%99%85%e7%9a%84%e5%9c%ba%e6%99%af%e4%b8%ad%e5%be%88%e5%b0%91%e4%bd%bf%e7%94%a8%0a%0a*%20**charset%e5%b1%9e%e6%80%a7%2c%e8%ae%be%e7%bd%ae%e9%a1%b5%e9%9d%a2%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81%e3%80%82**%0a%20%20%e6%ad%a4%e5%b1%9e%e6%80%a7%e6%8f%90%e4%be%9b%e4%ba%86%e4%bf%9d%e5%ad%98%e5%92%8c%e4%bc%a0%e8%be%93%e6%96%87%e6%a1%a3%e7%9a%84%e7%bc%96%e7%a0%81%e6%a0%bc%e5%bc%8f%e3%80%82%0a%20%20%3cmeta%20charset%3d%22utf-8%22%3e%0a%20%20%e7%ad%89%e4%bb%b7%e4%ba%8e%0a%20%20%3cmeta%20http-equiv%3d'content-type'%20content%3d'type%3dtext%2fhtml%3b%20charset%3dutf-8'%3e%0a%20%20%e4%bd%86%e6%98%af%e7%ac%ac%e4%b8%80%e7%a7%8d%e5%bd%a2%e5%bc%8f%e6%9b%b4%e7%ae%80%e6%b4%81%e5%a5%bd%e8%ae%b0%ef%bc%8c%e5%b9%b6%e4%b8%94%e5%be%97%e5%88%b0%e4%ba%86%e6%89%80%e6%9c%89%e4%b8%bb%e6%b5%81%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%94%af%e6%8c%81%ef%bc%8c%e6%89%80%e6%9c%89%e4%b8%8d%e5%ad%98%e5%9c%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e5%85%bc%e5%ae%b9%e9%97%ae%e9%a2%98%e3%80%82%e4%b8%ba%20%e4%ba%86%e8%ae%a9%e6%b5%8f%e8%a7%88%e5%99%a8%e8%83%bd%e5%87%86%e7%a1%ae%e8%af%86%e5%88%ab%e7%bc%96%e7%a0%81%e6%a0%bc%e5%bc%8f%ef%bc%8c%e5%8a%a1%e5%bf%85%e5%9c%a8%3ctitle%3e%e6%a0%87%e7%ad%be%e4%b9%8b%e5%89%8d%e8%ae%be%e7%bd%aecharset%2c%e4%bf%9d%e8%af%81%e6%a0%87%e9%a2%98%e8%83%bd%e6%ad%a3%e7%a1%ae%e6%98%be%e7%a4%ba%e3%80%82%0a%0a%20%20%20%20%20%20%e9%99%a4%e4%ba%86w3c%e5%ae%9a%e4%b9%89%e7%9a%84%e8%a7%84%e8%8c%83%e4%b8%ad%e5%ae%9a%e4%b9%89%e7%9a%84%e8%bf%99%e4%ba%9bmeta%e4%b9%8b%e5%a4%96%ef%bc%8c%e8%bf%98%e6%9c%89%e5%a4%a7%e9%87%8f%e7%9a%84%e8%87%aa%e5%ae%9a%e4%b9%89meta%e7%b1%bb%e5%9e%8b%e3%80%82%e8%bf%99%e4%ba%9bmeta%e7%b1%bb%e5%9e%8b%e4%b8%bb%e8%a6%81%e6%98%af%e7%94%b1%e4%ba%92%e8%81%94%e7%bd%91%e5%85%ac%e5%8f%b8%e6%88%96%e8%80%85%e6%b5%8f%e8%a7%88%e5%99%a8%e5%8e%82%e5%95%86%e4%b8%ba%e4%ba%86%e5%ae%9e%e7%8e%b0%e7%89%b9%e5%ae%9a%e7%9a%84%e5%8a%9f%e8%83%bd%e8%80%8c%e5%ae%9a%e5%88%b6%e7%9a%84%e3%80%82%e8%bf%99%e4%ba%9b%e8%87%aa%e5%ae%9a%e4%b9%89%e7%9a%84meta%e4%b8%8d%e8%83%bd%e9%80%9a%e8%bf%87w3c%e6%8f%90%e4%be%9b%e7%9a%84%e6%a0%87%e5%87%86%e6%a0%a1%e9%aa%8c%ef%bc%8c%e4%bd%86%e5%b9%b6%e4%b8%8d%e6%98%af%e8%af%b4%e8%bf%99%e4%ba%9bmeta%e4%b8%8d%e6%a0%87%e5%87%86%e3%80%82%e4%bb%8b%e7%bb%8d%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e7%9a%84meta%0a%0a%20%20**%e8%ae%be%e7%bd%aeie%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e5%85%bc%e5%ae%b9%e6%a8%a1%e5%bc%8f**%0a%20%20%20%e4%bb%8eie8%e6%b5%8f%e8%a7%88%e5%99%a8%e5%bc%80%e5%a7%8b%e6%94%af%e6%8c%81%e4%b8%80%e7%a7%8d%e8%ae%be%e7%bd%ae%e9%a1%b5%e9%9d%a2%e5%85%bc%e5%ae%b9%e6%a8%a1%e5%bc%8f%e7%9a%84meta%e7%b1%bb%e5%9e%8b%ef%bc%8c%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81%e5%a6%82%e4%b8%8b%3a%0a%20%20%20%3cmeta%20http-equiv%3d%22x-ua-compatible%22%20content%3d%22ie%3d8%22%2f%3e%0a%20%20%20%e6%a0%b9%e6%8d%aehtml%e8%a7%84%e8%8c%83%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%e6%98%af%e6%8c%89%e7%85%a7%e9%a1%b5%e9%9d%a2%e5%bc%80%e5%a4%b4%e5%ae%9a%e4%b9%89%e7%9a%84%e6%96%87%e6%a1%a3%e7%b1%bb%e5%9e%8b%e6%9d%a5%e8%a7%a3%e6%9e%90%e9%a1%b5%e9%9d%a2%e7%9a%84%e3%80%82%e4%be%8b%e5%a6%82%ef%bc%8c%e4%bd%bf%e7%94%a8html5%e7%9a%84%e6%96%87%e6%a1%a3%e7%b1%bb%e5%9e%8b%e5%a3%b0%e6%98%8e%ef%bc%9a%0a%20%20%20%3c!doctype%20html%3e%0a%20%20%20ie%e5%b0%b1%e4%bc%9a%e4%bb%a5%e6%a0%87%e5%87%86%e6%a8%a1%e5%bc%8f%e8%a7%a3%e6%9e%90html%e6%96%87%e6%a1%a3%e3%80%82%e4%bd%86%e6%98%af%e6%9f%90%e4%ba%9b%e5%b7%b2%e6%9c%89%e9%a1%b5%e9%9d%a2%e7%94%b1%e4%ba%8e%e5%90%84%e7%a7%8d%e5%8e%9f%e5%9b%a0%e4%b8%8d%e8%83%bd%e5%9c%a8%e6%9c%80%e6%96%b0%e6%a0%87%e5%87%86%e6%a8%a1%e5%bc%8f%e4%b8%8b%e6%ad%a3%e7%a1%ae%e6%98%be%e7%a4%ba%ef%bc%8c%e5%8f%aa%e6%94%af%e6%8c%81%e7%89%b9%e5%ae%9a%e7%9a%84%e6%a0%87%e5%87%86%e3%80%82%e9%92%88%e5%af%b9%e8%bf%99%e7%a7%8d%e6%83%85%e5%86%b5%ef%bc%8cie%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8f%90%e4%be%9b%e4%ba%86%e4%b8%80%e7%a7%8d%e5%85%bc%e5%ae%b9%e7%9a%84%e6%96%b9%e6%a1%88%ef%bc%8c%e9%80%9a%e8%bf%87%e8%ae%be%e7%bd%aex-ua-compatible%e6%8c%87%e5%ae%9a%e9%a1%b5%e9%9d%a2%e5%9c%a8ie%e6%b5%8f%e8%a7%88%e5%99%a8%e4%b8%ad%e6%b8%b2%e6%9f%93%e6%97%b6%e6%89%a7%e8%a1%8c%e7%9a%84%e6%a0%87%e5%87%86%e3%80%82%0a%20%20%20%e6%ad%a4%e5%a4%96%e8%bf%98%e6%9c%89%e4%b8%80%e7%a7%8d%e5%be%88%e5%b8%b8%e8%a7%81%e7%9a%84%e8%ae%be%e7%bd%ae%e5%80%bc%ef%bc%8c%e5%8d%b3%3a%0a%20%20%20%3cmeta%20http-equiv%3d%22x-ua-compatible%22%20content%3d%22chrome%3d1%22%2f%3e%0a%20%20%20ie%e5%ae%9a%e4%b9%89%e7%9a%84meta%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bc%9a%e5%87%ba%e7%8e%b0chrome%e5%91%a2%ef%bc%9f%e5%85%b6%e5%ae%9e%e8%ae%be%e7%bd%ae%e4%b8%bachrome%3d1%e6%97%b6%ef%bc%8c%e5%88%99%e4%bc%9a%e5%9c%a8ie9%e5%8f%8a%e4%bb%a5%e4%b8%8b%e6%b5%8f%e8%a7%88%e5%99%a8%e4%b8%ad%e6%bf%80%e6%b4%bbchrome%20frame%2c%e5%bc%ba%e5%88%b6ie%e4%bd%bf%e7%94%a8chrome%20frame%e6%b8%b2%e6%9f%93%e9%a1%b5%e9%9d%a2%e3%80%82%0a