html元素之meta

介绍

meta元素也被称之为元数据,主要有两方面作用:

  • 定义文档信息

  • 定义浏览器动作

meta中name和content属性的html实体编码不会解码

文档信息

可以任意定义,不具有效应,当然,最好遵循公共的命名规则。

<meta name="referrer" content="origin-when-crossorigin">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="report" content="{&quot;pid&quot;: &quot;blog&quot;, &quot;spm&quot;:&quot;1001.2101&quot;}">
<meta name="applicable-device" content="pc">
<meta name="renderer" content="webkit">

浏览器动作

具有效应,会被浏览器解析然后进行一定的动作

1、刷新

<meta http-equiv="refresh" content="5;url=http://www.w3school.com.cn">
<meta http-equiv="Refresh" content="n;url=http://yourlink">

5秒钟后跳转
该标签可用于head,也可以用于body
2、类型和编码

<meta http-equiv="Content-Type" content="text/html;charset=gb_2312-80">
<meta http-equiv="Content-Language" content="zh-CN">

用以说明主页制作所使用的文字以及语言;又如英文是ISO-8859-1字符集,还有BIG5、utf-8、shift-Jis、Euc、Koi8-2等字符集;

3、过期时间

<meta http-equiv="Expires" content="Mon,12 May 2001 00:20:00 GMT">

可以用于设定网页的到期时间,一旦过期则必须到服务器上重新调用。需要注意的是必须使用GMT时间格式;

<meta http-equiv="Pragma" content="no-cache">

是用于设定禁止浏览器从本地机的缓存中调阅页面内容,设定后一旦离开网页就无法从Cache中再调出;

4、设置cookie

<meta http-equiv="set-cookie" content="Mon,12 May 2001 00:20:00 GMT">

cookie设定,如果网页过期,存盘的cookie将被删除。需要注意的也是必须使用GMT时间格式。

<meta http-equiv="Set-Cookie" content="cookievalue=xxx;expires=Wednesday, 20-Jun-200722:33:00 GMT; path=/">

不能在html页面中使用,浏览器控制台报错误:

Blocked setting the cookievalue=xxx;expires=Wednesday,21-Oct-98 16:14:21 GMT; path=/ cookie from a <meta> tag.
5、网页等级评定

<meta http-equiv="Pics-label" content="">

网页等级评定,在IE的internet选项中有一项内容设置,可以防止浏览一些受限制的网站,而网站的限制级别就是通过meta属性来设置的;

6、独立加载

<meta http-equiv="windows-Target" content="_top">

强制页面在当前窗口中以独立页面显示,可以防止自己的网页被别人当作一个frame页调用;

7、特殊效果

<meta http-equiv="Page-Enter" content="revealTrans(duration=10,transition= 50)">
<meta http-equiv="Page-Exit" content="revealTrans(duration=20,transition=6)">

设定进入和离开页面时的特殊效果,这个功能即FrontPage中的"格式/网页过渡",不过所加的页面不能够是一个frame页面。

8、编码

<meta charset="utf-8">

这里设置的charset,是为浏览器指导html页面的编码

注意:对于中文网页需要使用 声明编码,否则会出现乱码。有些浏览器(如 360 浏览器)会设置 GBK 为默认编码 。

posted @ 2022-05-10 12:17  黑白猫123  阅读(226)  评论(0编辑  收藏  举报