HTML的meta标签

meta 标签 -- 在head标签中的meta标签,可以为HTML文档提供额外信息
  • 此标签是单独出现的,<meta />
  • 此标签只能出现在head标签内
  • 属性:
  • meta的英文翻译为"元"
  • meta是metainformation的缩写

meta属性主要分为两组

name属性与content属性

name属性用于描述网页,它是以名称/值形式的名称,name属性的值所描述的内容(值)通过content属性表示,便于搜索引擎机器人查找,分类.其中最重要的是description,keywordsrobots.

http-equiv属性与content属性

http-equiv属性用于提供HTTP协议的响应头报文(MIME文档头),它是以名称/值形式的名称,http-equiv属性的值所描述的内容(值)通过content属性表示,通常为网页加载前提供给浏览器等设备使用.其中最重要的是content-type charset 提供编码信息,refresh刷新与跳转页面,no-cache 页面缓存,expires网页缓存过期时间.

 

HTML meta content-type 定义文件MIME类型

content-type 属性值 -- 定义文件MIME类型
  • content-type用于定义用户的浏览器或相关设备如何显示将要加载的数据,或者如何处理将要加载的数据,此属性的值可以查看MIME类型
  • content-language出现在http-equiv属性中,使用content属性表示页面的MIME类型

content-type语法

Content-Type := type "/" subtype *[";" parameter]

content-type实例

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-type" content="text/html; charset=gb2312" />


HTML meta content-language 定义页面语言

content-language 属性值 -- 定义页面语言
  • content-language用于定义页面所使用的语言代码
  • content-language出现在http-equiv属性中,使用content属性表示页面的语言以及国家代码

content-language语法

language-code = primary-code ( "-" subcode )*

content-language示例

<meta http-equiv="content-language" content="zh-CN" />

 

例如:language-code为"en"时,代表English英文,而language-code为"en-US"时,代表the U.S. version of English美国版本的英文.

primary-code为语言代码,subcode为国家代码

primary-code为两个字母组成常用的有

  • zh (Chinese)中国
  • fr (French)法国
  • de (German)德国
  • it (Italian)意大利
  • nl (Dutch)荷兰
  • el (Greek)希腊
  • es (Spanish)西班牙
  • pt (Portuguese)葡萄牙
  • ar (Arabic)阿拉伯
  • ru (Russian)俄罗斯
  • ja (Japanese)日本

HTML meta refresh 刷新与跳转(重定向)页面

refresh 属性值 -- 刷新与跳转(重定向)页面
  • refresh用于刷新与跳转(重定向)页面
  • refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址

refresh示例

5秒之后刷新本页面:

<meta http-equiv="refresh" content="5" />

5秒之后转到百度首页:

<meta http-equiv="refresh" content="5; url=http://www.baidu.com/" />

HTML meta expires 网页缓存过期时间

expires 属性值 -- 网页缓存过期时间
  • expires用于网页缓存过期时间
  • expires出现在http-equiv属性中,使用content属性表示页面缓存的过期时间

expires用于设定网页的过期时间,一旦过期就必须从服务器上重新加载.时间必须使用GMT格式.

expires示例

<meta http-equiv="expires" content="Sunday 26 October 2008 01:00 GMT" />

HTML meta pragma no-cache 页面缓存

pragma与no-cache 属性值 -- 定义页面缓存
  • pragma与no-cache用于定义页面缓存
  • pragma出现在http-equiv属性中,使用content属性的no-cache值表示是否缓存网页

不缓存页面(为了提高速度一些浏览器会缓存浏览者浏览过的页面,通过下面的定义,浏览器一般不会缓存页面,而且浏览器无法脱机浏览.)

pragma

<meta http-equiv="pragma" content="no-cache" />

HTML meta keywords 网页关键词

keywords 属性值 -- 定义网页关键词
  • keywords用于定义网页关键词
  • keywords出现在name属性中,使用content属性提供网页的关键词

keywords示例

<meta name="keywords" content="HTML XHTML" />

HTML meta description 网页简短描述

description 属性值 -- 定义网页简短描述
  • description用于定义网页简短描述
  • description出现在name属性中,使用content属性提供网页的简短描述

description示例

<meta name="description" content="html教程,完善的html内容,使初学者迅速掌握html的精髓,猴子编写的梦之,都html教程" />
<meta name="description" content="html toturial and html books" />

上面示例使用了中文与英文定义页面的简短描述

description的使用说明

  • description提供的网页简短描述通常是为搜索引擎描述网页使用的;
  • 网页简短描述不能太长,应该保持在140-200个字符或者100个左右的汉字;
  • 不要给网页定义与网页描述内容无关的简短描述;
  • 由于网页制作者滥用description(提供与网页无关的简短描述),导致目前常用的搜索引擎降低了description的重要性。

HTML meta author 网页作者

author 属性值 -- 定义网页作者
  • author用于定义网页作者
  • author出现在name属性中,使用content属性提供网页的作者

author示例

<meta name="author" content="http://www.dreamdu.com/blog/" />

HTML meta copyright 网页版权

copyright 属性值 -- 定义网页版权
  • copyright用于定义网页版权
  • copyright出现在name属性中,使用content属性提供网页的版权

copyright示例

<meta name="copyright" content="© http://www.dreamdu.com" />

HTML meta date 网页生成时间

date 属性值 -- 定义网页生成时间
  • date用于定义网页生成时间
  • date出现在name属性中,使用content属性提供网页的生成时间

date示例

<meta name="date" content="2008-07-12T20:50:30+00:00" />
定义网页的的生成时间为2008年7月12日。

HTML meta robots 搜索引擎索引方式

robots 属性值 -- 定义网页搜索引擎索引方式
  • robots用于定义网页搜索引擎索引方式
  • robots出现在name属性中,使用content属性定义网页搜索引擎索引方式
  • 通过使用meta的robots属性值可以为没有文件上传权限的用户提供/robots.txt文件的所有功能

robots语法

<meta name="robots" content="robotterms" />

robotterms是一组使用逗号(,)分割的值,通常有如下几种取值:none,noindex,nofollow,all,index和follow。

robots取值

none
搜索引擎将忽略此网页,等价于noindexnofollow
noindex
搜索引擎不索引此网页。
nofollow
搜索引擎不继续通过此网页的链接索引搜索其它的网页。
all
搜索引擎将索引此网页与继续通过此网页的链接索引,等价于indexfollow
index
搜索引擎索引此网页。
follow
搜索引擎继续通过此网页的链接索引搜索其它的网页。

robots的使用说明

  • robots提供的搜索引擎对网页的索引方式 http://www.dreamdu.com/xhtml/meta_robots/;
  • 如果网页没有提供robots,搜索引擎认为网页的robots属性为all(index,follow);

robots常用示例

<meta name="robots" content="noindex" />

上面示例定义了此网页不被搜索引擎索引进数据库,但搜索引擎可以通过此网页的链接继续索引其它网页

<meta name="robots" content="nofollow" />

上面示例定义了梦之都此网页被搜索引擎索引进数据库,但搜索引擎不可以通过此网页的链接继续索引其它网页

<meta name="robots" content="none" />

上面示例定义了此网页不被搜索引擎索引进数据库,且搜索引擎不可以通过此网页的链接继续索引其它网页

针对谷歌GOOGLEBOT使用robots

可以将name的属性只定义为GOOGLEBOT标识为谷歌搜索引擎。 使用元标记拦截或删除网页

<meta name="googlebot" content="noindex, nofollow" />

针对百度baiduspider使用robots

可以将name的属性只定义为baiduspider标识为百度搜索引擎。禁止搜索引擎收录的方法

<meta name="baiduspider" content="noarchive" />
 

 

posted @ 2016-06-20 16:36  逝意遨游  阅读(322)  评论(0编辑  收藏  举报