关于html meta标签设置

META标签分两大部分:HTTP标题信息(http-equiv)和页面描述信息(name)。

http-equiv

http-equiv类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助正确和精确地显示网页内容。

  • 设置页面编码 charset

UTF-8是世界性通用编码,也完美的支持中文编码

GB2312属于中文编码,针对国内用户使用,国外用户访问GB2312编码的网站就会变乱码。

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设置字符编码</title>
</head>
<body>

</body>
</html></pre>

  • 设置页面刷新时间 refresh

让网页多长时间自动刷新,或者多长时间后让网页自动链接到其他网页,单位:秒

不添加URL就本地刷新


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="3;url=https://www.baidu.com">
    <title>刷新</title>
</head>
<body>
    <p>设置网页3秒后跳转百度页面</p>
</body>
</html></pre>

  • 设置网页缓存时间 expires

设置网页在缓存时间过期时间,一旦网页过期,就需要在服务器上重新加载

必须使用GMT的时间格式(格林尼治标准时间),或者直接设为0,数字表示多少时间后过期


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv=expires content=Thu,15 Apr  2010  20:00:00  GMT>
    <title>缓存</title>
</head>
<body>
    <p>Thu,15 Apr  2010  20:00:00  GMT;  
    他告诉浏览器缓存有效性持续到2010年4月15日为止,在这个时间之内相同的请求使用缓存,这个时间之外使用http请求。</p>
</body>
</html></pre>

  • 禁止页面缓存 pragma(cach模式)

禁止浏览器从本地的缓存中调阅页面的内容

网页不保存在缓存中,每次访问都刷新页面,访问者无法脱机浏览


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="pragma" content="no-cach">
    <title>禁止缓存</title>
</head>
<body>

</body>
</html></pre>

  • Set-Cookie (cookie设定)

浏览器访问某个页面时会将它存在缓存中,下次再次访问时就可从缓存中读取,以提高速度。当你希望访问者每次都刷新你广告的图标,或每次都刷新你的计数器,就要禁用缓存了。通常HTML文件没有必要禁用缓存,对于ASP等页面,就可以使用禁用缓存,因为每次看到的页面都是在服务器动态生成的,缓存就失去意义。如果网页过期,那么存盘的cookie将被删除。

注意:必须使用GMT的时间格式。


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <Meta http-equiv=Set-Cookie Content=cookievalue=xxx; expires=Wednesday,21-Oct-98 16:14:21 GMT; path= />
    <title>Set-Cookie</title>
</head>
<body>

</body>
</html></pre>

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

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

这个属性是用来防止别人在框架里调用你的页面。

<caption style="margin: 0px; padding: 0px;">Content选项:</caption>
| _blank | 在新窗口中打开被链接的文档 |
| _self | 默认。在相同的框架中打开被链接的文档 |
| _top | 在整个窗口中打开被链接的文档 |
| _parent | 在父框架集中打开被链接文档 |
| framname | 在指定框架中打开被链接的文档 |


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv=widow-target Content=_top>
    <title>显示窗口设定</title>
</head>
<body>

</body>
</html></pre>

NAME变量

name是描述网页的,对应于content(网页内容),以便于搜索引擎机器人查找、分类(目前几乎所有的搜索引擎都使用网上机器人自动查找meta值来给网页分类)。

name的value值(name=)指定所提供信息的类型。有些值是已经定义好的。例如description(说明)、keyword(关键字)、refresh(刷新)等。还可以指定其他任意值,如:creationdate(创建日期) 、

document ID(文档编号)和level(等级)等。

name的content指定实际内容。如:如果指定level(等级)为value(值),则Content可能是beginner(初级)、intermediate(中级)、advanced(高级)。

  • Keywords (关键字)

说明:为搜索引擎提供的关键字列表

用法:<Meta name=Keywords Content=关键词1,关键词2,关键词3,关键词4,……>

各关键词间用英文逗号“,”隔开。META的通常用处是指定搜索引擎用来提高搜索质量的关键词。当数个META元素提供文档语言从属信息时,搜索引擎会使用lang特性来过滤并通过用户的语言优先参照来显示搜索结果。


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=kyewords lang=en content=关键字,关键字,关键字>
    <title>网页关键字</title>
</head>
<body>

</body>
</html></pre>

  • Description (简介)

Description用来告诉搜索引擎你的网站主要内容。


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=description content=你网页的简述>
    <title>网页的简述</title>
</head>
<body>

</body>
</html></pre>

  • Robots (机器人向导)

Robots用来告诉搜索机器人哪些页面需要索引,哪些页面不需要索引。

许多搜索引擎都通过放出robot/spider搜索来登录网站,这些robot/spider就要用到meta元素的一些特性来决定怎样登录。

<caption style="margin: 0px; padding: 0px;">Content的参数</caption>
|

all

| 文件将被检索,且页面上的链接可以被查询; |
|

none

| 文件将不被检索,且页面上的链接不可以被查询;(和 noindex, no follow 起相同作用) |
|

index

| 文件将被检索;(让robot/spider登录) |
|

follow

| 页面上的链接可以被查询; |
|

noindex

| 文件将不被检索,但页面上的链接可以被查询;(不让robot/spider登录) |
| nofollow | 文件将不被检索,页面上的链接可以被查询。(不让robot/spider顺着此页的连接往下探找) |


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=robots content=all>
    <title>Robots</title>
</head>
<body>

</body>
</html></pre>

  • Author (作者)

标注网页的作者或制作组

Content可以是:你或你的制作组的名字,或Email


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=author content=修抗,www.1778895866@qq.com>
    <title>网页的作者</title>
</head>
<body>

</body>
</html></pre>

  • Copyright (版权)

标注版权


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=copyright content=本页版权归修抗个人所有。All Rights Reserved>
    <title>网页的版权</title>
</head>
<body>

</body>
</html></pre>

  • 6、Generator (编辑器)

编辑器的说明

Content=你所用编辑器


<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name=generator content=sublime>
    <title>编写网页使用的编辑器</title>
</head>
<body>

</body>
</html></pre>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,451评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,172评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,782评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,709评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,733评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,578评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,320评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,241评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,686评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,878评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,992评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,715评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,336评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,912评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,040评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,173评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,947评论 2 355

推荐阅读更多精彩内容