Skip to main content

meta标签详解

作用

  • 搜索引擎(SEO)优化
  • 定义页面使用语言
  • 自动刷新页面
  • 控制页面缓存
  • 页面定级评价
  • 控制页面显示的窗口
  • ...

meta 属性

标签一共有三个属性,不同的属性和值组成了网页不同的功能

  • name
  • http-equiv
  • content

name属性

name属性用于描述网页,对应content属性中内用是便于搜索引擎查找和分类信息,语法:

<meta name="" content="">
name="keywords"

用来设置让搜索引擎获取网页的关键字

<meta name="keywords" content="活动,聚会,拓展,团建,培训,讲座">
name="description"

用来设置让搜索引擎获取网页的内容描述

<meta name="description" content="这是我这个网页的一些描述信息,搜索引擎可以根据我的描述信息进行分类我网页">
name="robots"

它是用来设置,让搜索引擎那些页面需要索引,那些页面不需要索引,content参数如下:

  • all:文件将被检索,且页面上的链接可以被查询
  • none:文件将不被检索,且页面上的链接不可以被查询
  • index:文件将被检索
  • noindex:文件将不被检索,但页面上的链接可以被查询
  • follow:页面上的链接可以被查询
  • nofollow:文件将被检索,页面上的链接不可以被查询
<meta name="robots" conotent="all"/>
name="author"

用来设置页面的作者

<meta name="author" content="jay"/>
name="generator"

用来设置网站采用了什么软件制作的

<meta name="generator" content="shoulu"/>
name="COPYRIGHT"

设置网站的版权信息

<meta name="COPYRIGHT" content="版权公司"/>
name="revisit-after"

用来设置网站的重访 30day代表三十天

<meta name="revisit-after" content="30day"/>
name="viewport"

用来控制浏览器窗口的大小和缩放的,由于它在现代浏览器,特别是Mobiledaunt浏览器中非常有用

<meta name="viewport"  content="width=device-width,init-scale=1,maxmum-scale=1"/>

http-equiv

http-equiv相当于HTTP的文件头设置,语法:

<meta http-equiv="" content=""/>
http-equiv="expires"

用来设置网页的过期时间

<meta http-equiv="expires" content="Fri May 13 2020 22:49:44 GMT+0800 (CST)"/>
http-equiv="Refresh"

用来设置自动刷新并跳转新页面,其中content第一个数字代表五秒后自动刷新

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

设置cookie

<meta name="Set-Cookie" content="cookie value=xxx;expires=Frigay,12-Jan-200118:18:18GMT;path=/"/>
http-equiv="Window-target"

强制在当前窗口以独立页面显示

<meta http-equiv="Window-target" content="top"/>
http-equiv="content-type"

设置页面使用的字符集

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

设置页面的语言

<meta http-equiv="content-language" content="zh-cn"/>
http-equiv="Cache-Control"

设置页面的缓存,可以设置多种缓存机制

<meta http-equiv="Cache-Control" content="no-cache"/>
http-equiv="Content-Script-type"

设置页面中脚本的类型

<meta http-equiv="Content-Script-Type" content="text/javascript"/>