html学习笔记之meta 标签介绍

来源:互联网 发布:王啸坤 长白山 知乎 编辑:程序博客网 时间:2024/04/29 19:13

原文:html学习笔记之meta 标签介绍

在html中常常要用到meta 标签 -- 在head标签中的meta标签,可以为HTML文档提供额外信息,所以这里NanShan跟大家一起探讨
下meta 标签的前世今生。
此标签是单独出现的,<meta />
此标签只能出现在head标签内
属性:
I18N -- i18n属性
xml:lang -- 国际化属性
content -- content属性
http-equiv -- http-equiv属性
id -- id属性
name -- name属性
scheme -- scheme属性
meta的英文翻译为"元"
meta是metainformation的缩写
HTML meta charset 定义网页编码信息
使用http-equiv的content-type可以提供网页的编码信息
charset示例
使用UTF8编码(国际化编码)
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
使用中文gb2312编码
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
下面这些编码方式,比如:中文 GBK ,繁体中文 Big5 ,日文 EUC-JP ,韩文 EUC-KR 等,每种语言的编码方式是不同的,所以需要使用charset为网页提供了一种编码方式,否则页面很可能出现乱码.
UTF-8 是没有国家的编码,也就是独立于任何一种语言,任何语言都可以使用

HTML meta content-type 定义文件MIME类型
content-type 属性值 -- 定义文件MIME类型
content-type用于定义用户的浏览器或相关设备如何显示将要加载的数据,或者如何处理将要加载的数据,此属性的值可以查看MIME类型
content-language出现在http-equiv属性中,使用content属性表示页面的MIME类型
content-type语法
Content-Type := type "/" subtype *[";" parameter]
type的常见取值为application audio image message multipart text video

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=hp://www.sina.com.cn/" />

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教程" />
<meta name="description" content="html toturial and html books" />

HTML meta author 网页作者
author 属性值 -- 定义网页作者
author用于定义网页作者
author出现在name属性中,使用content属性提供网页的作者
author示例
<meta name="author" content="hp://bg.sina.com.cn" />

HTML meta copyright 网页版权
copyright 属性值 -- 定义网页版权
copyright用于定义网页版权
copyright出现在name属性中,使用content属性提供网页的版权
copyright示例
<meta name="copyright" content="© hp://blog.sina.com.cn/" />

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
搜索引擎将忽略此网页,等价于noindex,nofollow。
noindex
搜索引擎不索引此网页。
nofollow
搜索引擎不继续通过此网页的链接索引搜索其它的网页。
all
搜索引擎将索引此网页与继续通过此网页的链接索引,等价于index,follow。
index
搜索引擎索引此网页。
follow
搜索引擎继续通过此网页的链接索引搜索其它的网页。
robots的使用说明
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" />
copyright 属性值 -- 定义网页版权
copyright用于定义网页版权
copyright出现在name属性中,使用content属性提供网页的版权
copyright示例
<meta name="copyright" content="© hp://blog.sina.com.cn/" />


HTML meta date 网页生成时间
date 属性值 -- 定义网页生成时间
date示例
<meta name="date" content="2008-07-12T20:50:30+00:00" />
date用于定义网页生成时间
date出现在name属性中,使用content属性提供网页的生成时间

1 0