Fork me on GitHub
文章目录
  1. 1. meta的name属性
    1. 1.1. Keywords(关键字)
    2. 1.2. description(网站内容描述)
    3. 1.3. robots(机器人向导)
    4. 1.4. author(作者)
  2. 2. meta的http-equiv
    1. 2.1. Expires(期限)
    2. 2.2. Pragma(cache模式)
    3. 2.3. Refresh(刷新)
    4. 2.4. Set-Cookie(cookie设定)
    5. 2.5. Window-target(显示窗口的设定)
    6. 2.6. content-Type(显示字符集的设定)
    7. 2.7. Page-Exit /Page-Enter(进入页面、离开页面动画效果)
  3. 3. meta扩展的标签
    1. 3.1. 使用Open Graph Protocol应注意
  4. 4. 参考文章

meta提供关于HTML文档的元数据。元数据不会显示在页面上,但是对于机器是可读的。它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他web服务。 —— W3School

网页头部有两个标签titel和meta, title比较简单,就是网页标题,meta的内容还是蛮多的,在此总结一下。

meta共有两个属性,它们分别是name属性和http-equiv属性,不同的属性又有不同的参数值,这些不同的参数值就实现了不同的网页功能。meta在HTML5中又扩展了新的标签如meta property=og.

meta的name属性

name属性主要用于描述网页,与之对应的属性值为content,content中的内容主要是便于搜索引擎机器人查找信息和分类信息用的。meat标签的name属性语法格式是:<meta name="参数" content="具体的参数值">

其中name属性主要有以下几种参数:

Keywords(关键字)

说明:keywords用来告诉搜索引擎你网页的关键字是什么。
举例:<meta name ="keywords" content="science, education,culture,politics,relationships,human">

description(网站内容描述)

说明:description用来告诉搜索引擎你的网站主要内容。
举例:<meta name="description" content="This page is about the meaning of science,education,culture.">

robots(机器人向导)

说明:robots用来告诉搜索机器人哪些页面需要索引,哪些页面不需要索引。content的参数有all,none,index,noindex,follow,nofollow。默认是all。

1
2
3
4
5
6
7
8
<meta name="robots" content="index,follow" />
<!--
all:文件将被检索,且页面上的链接可以被查询;
none:文件将不被检索,且页面上的链接不可以被查询;
index:文件将被检索;
follow:页面上的链接可以被查询;
noindex:文件将不被检索;
nofollow:页面上的链接不可以被查询。-->

author(作者)

说明:标注网页的作者
举例:<meta name="author" content="***@yahoo.com.con">

meta的http-equiv

http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就是各个参数的变量值。
meat标签的http-equiv属性语法格式是:<meta http-equiv="参数" content="参数变量值">

其中http-equiv属性主要有以下几种参数:

Expires(期限)

说明:可以用于设定网页的到期时间。一旦网页过期,必须到服务器上重新传输。
用法:<meta http-equiv="expires" content="Fri, 12 Jan 2014 18:18:18 GMT"> 必须使用GMT的时间格式。

Pragma(cache模式)

说明:禁止浏览器从本地计算机的缓存中访问页面内容。
用法:<meta http-equiv="Pragma" content="no-cache">
注意:这样设定,访问者将无法脱机浏览。

Refresh(刷新)

说明:自动刷新并指向新页面。
用法:<meta http-equiv="Refresh" content="2;URL=http://phigo.bokee.com">
注意:其中的2是指停留2秒钟后自动刷新到URL网址。

Set-Cookie(cookie设定)

说明:如果网页过期,那么存盘的cookie将被删除。
用法:<meta http-equiv="Set-Cookie" content="cookievalue=xxx; expires=Fri, 12 Jan 2014 18:18:18 GMT; path=/">
注意:必须使用GMT的时间格式。

Window-target(显示窗口的设定)

说明:强制页面在当前窗口以独立页面显示。
用法:<meta http-equiv="Window-target" content="_top">
注意:用来防止别人在框架里调用自己的页面。

content-Type(显示字符集的设定)

说明:设定页面使用的字符集。
用法:<meta http-equiv="content-Type" content="text/html; charset=UTF-8">

Page-Exit /Page-Enter(进入页面、离开页面动画效果)

使用meta标签,我们还可以在进入网页或者离开网页的一刹那实现动画效果,我们只要在页面的html代码中的<head></head>标签之间添加如下代码就可以了:
<meta http-equiv="Page-Enter" content="revealTrans(duration=5, transition=23)">
<meta http-equiv="Page-Exit" content="revealTrans(duration=5, transition=23)">
一旦上述代码被加到一个网页中后,我们再进出页面时就会看到一些特殊效果,这个功能其实与FrontPage2000中的Format/Page Transition一样,但我们要注意的是所加网页不能是一个Frame页;Duration的值为网页动态过渡的时间,单位为秒。Transition是过渡方式,它的值为0到23,分别对应24种过渡方式。(此处不一一例举了)

meta扩展的标签

比如Meta Property=og标签,og是一种新的HTTP头部标记,即Open Graph Protocol,这种协议可以让网页成为一个“富媒体对象”。用了Meta Property=og标签,就是你同意了网页内容可以被其他社会化网站引用等,目前这种协议被SNS网站如Fackbook、renren采用。而该标签能够正确且更有效地将你的内容分享到SNS网站。

1
2
3
4
5
6
7
<meta property=”og:type” content=”video”/>
<meta property=”og:title” content=”五月天_突然好想你MV现场版”/>
<meta property=”og:image” content=”http://g1.ykimg.com/***.jpg″/>
<meta property=”og:url” content=”http://v.youku.com/v_show/id_XMTIyMTY5NzMy.html”/>
<meta property=”og:videosrc” content=”http://player.youku.com/player.php/sid/***.swf”/>
<meta property=”og:width” content=”500″ />
<meta property=”og:height” content=”416″ />

另外meta还有其他的扩展标签,如

1
2
3
4
<meta property="qc:admins" content="77103107776553571676375" />
<!--配置第三方QQ登录的验证码 -->
<meta property="wb:webmaster" content="c4f857219bfae3cb" />
<!--配置第三方Sina登录的验证码 -->

使用Open Graph Protocol应注意

meta property=og代码的功能并不等同于网页的meta name标签,两者针对的对象不一致,功能不同。
如果网站上要使用Open Graph Protocol,那么,meta property=og和meta name、Title标签应同时赋值。
文章开头举例的B2C网站,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<head>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ />
<title>Cool Gadgets at the Right Price – Worldwide Free Shipping – ******</title>
<meta property=”og:title” content=”**’sFacebook” />
<meta property=”og:type” content=”product”/>
<meta property=”og:url” content=”http://www.******.com” />
<meta property=”og:image” content=”http://www.******.com/logo.gif”/>
<meta property=”og:site_name” content=”******.com” />
<meta property=”og:description” content=”CoolGadgets at the RightPriceWorldwide Free Shipping – ******”/>
<meta property=”fb:admins” content=”100001422224225″ />
<meta property=”fb:page_id” content=”241333394220″/>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ />
<meta name=”description” content=”Online shopping for cool gadgets at the right price. ” />
<meta name=”keywords” content=”cool gadgets, cheap gadgets, free shipping” />
</head>

参考文章

  1. 常用meta整理
  2. 网页头部标签meta详解
  3. 在HTML中使用meta标签的基础知识和最佳实践
文章目录
  1. 1. meta的name属性
    1. 1.1. Keywords(关键字)
    2. 1.2. description(网站内容描述)
    3. 1.3. robots(机器人向导)
    4. 1.4. author(作者)
  2. 2. meta的http-equiv
    1. 2.1. Expires(期限)
    2. 2.2. Pragma(cache模式)
    3. 2.3. Refresh(刷新)
    4. 2.4. Set-Cookie(cookie设定)
    5. 2.5. Window-target(显示窗口的设定)
    6. 2.6. content-Type(显示字符集的设定)
    7. 2.7. Page-Exit /Page-Enter(进入页面、离开页面动画效果)
  3. 3. meta扩展的标签
    1. 3.1. 使用Open Graph Protocol应注意
  4. 4. 参考文章