最近在w3回看了HTML的meta标签,在这儿跟各位分享一下。
meta是什么?
meta是指HTML文件的meta-data(中介数据),用作HTML文件的属性描述。
1. 标准属性name及content
(a) 网页对应的应用程序名字,e.g. UserManagementSystem
<meta name="application-name" content="UserManagementSystem" />
(b) 网页的作者,e.g. Peter
<meta name="author" content="Peter" />
(c) 网页说明,e.g. Login Page
<meta name="description" content="Login Page" />
(d) 生成网页的工具名称,e.g. Microsoft Word 2007。
<meta name="generator" content="Microsoft Word 2007" />
(e) 网页的关键字,e.g. login,user,password
<meta name="keywords" content="login,user,password" />
2. 浏览器预处理指令http-equiv
(a) 内容格式,e.g. text/html;charset=big5
<meta http-equiv="content-type" content="text/html;charset=big5" />
(b) 内容的样式类型,e.g. text/css。
<meta http-equiv="content-style-type" content="text/css" />
(c) 内容的脚本类型,e.g. text/javascript
<meta http-equiv="content-script-type" content="text/javascript" />
(d) 预设样式,对应link或者style标签的title,e.g.MyDefaultStyle
<meta http-equiv="default-style" content="MyDefaultStyle" />
(e) 自动刷新,e.g.10秒;如果没有定义url,会刷新本页面;否者,刷新到url
<meta http-equiv="refresh" content="10;url=http://www.google.com; />
(f) 指示浏览器勿缓存本页面
<meta http-equiv="pragma" content="no-cache" />
(g) 指示本页必须是最高的window frame,不支持透过iframe或者frame加载
<meta http-equiv="window-target" content="_top" />
(h) 设置浏览器的cookie
<meta http-equiv="set-cookie" content="MyName=Peter;path=/;expires=01-Jan-2015 00:00:00 GMT" />
(i) 设置浏览器缓存本页的限期
<meta http-equiv="expires" content="01-Jan-2015 00:00:00 GMT" />
3. 预设编码charset
所有支持的charset都可以在IANA的网页上找到。
http://www.iana.org/assignments/character-sets/character-sets.xhtml
<meta charset="utf-8" />
4. 指示搜索引擎爬虫的行为robots
预设为index,follow。index的意思是允许爬虫为本页设置索引;follow是允许爬虫根据本页的连接继续往下爬。
此外,我们也可以透过robots.txt文件设置爬虫在整个网站的行为。
详情:http://www.robotstxt.org
<meta name="robots" content="index,nofollow" />