web前端

meta 标签大全

2018-07-31  本文已影响52人  索隆萨克

引用地址1
引用地址2
保存下来,以便查阅

什么是meta标签?


属性名区域:

content 属性 必选属性
始终要和 name 属性或 http-equiv 属性一起使用。即而是当有http-equiv或name属性的时候,一定要有content属性对其进行说明。

<!-- 示例见keywords -->

name 属性 可选属性
这个属性是供浏览器进行解析,对于一些浏览器兼容性问题,name属性是最常用的,当然有个前提就是浏览器能够解析你写进去的name属性才可以,不然就是没有意义的。

<meta name="renderer" content="webkit">

http-equiv 属性 可选属性
指示服务器在发送实际的文档之前先在要传送给浏览器的 MIME 文档头部包含名称/值对。当服务器向浏览器发送文档时,会先发送许多名称/值对。虽然有些服务器会发送许多这种名称/值对,但是所有服务器都至少要发送一个:content-type:text/html。这将告诉浏览器准备接受一个 HTML 文档。使用带有 http-equiv 属性的 <meta> 标签时,服务器将把名称/值对添加到发送给浏览器的内容头部

<meta http-equiv="charset" content="iso-8859-1">
<meta http-equiv="expires" content="31 Dec 2008">
<!--  
发送到浏览器的头部就会包含
content-type: text/html
charset:iso-8859-1
expires:31 Dec 2008
 -->

scheme 属性 可选属性
用于指定要用来翻译属性值的方案。此方案应该在由 <head> 标签的 profile 属性指定的概况文件中进行了定义。
charset
charset是声明文档使用的字符编码,解决乱码问题主要用的就是它,值得一提的是,这个charset一定要写第一行,不然就可能会产生乱码了。

<!--  charset有两种写法 -->
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

属性值区域:

keywords,description(常用的两个)

<meta name="keywords" content="HTML,CSS,JAVASCRIPT,PHP">
<meta name="description" content="html meta标签大全,整理一下加强记忆">

Content-Type
告诉浏览器当前访问的资源类型

<!--告诉浏览器当前访问的资源类型 并声明编码-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

refresh
重定向(以下示例,5秒后会跳转到:http://blog.csdn.net

<meta http-equiv="refresh" content="5;url=http://blog.csdn.net" />

full-screen
全屏显示网页(部分移动端浏览器的专有属性)

<meta name="full-screen" content="yes"/>

browsermode
浏览器模式-强制竖屏显示(部分移动端浏览器的专有属性)

<meta name="browsermode" content="application"/>

format-detection
数据格式验证渲染:
telephone:而iPhone会自动把你这个文字加链接样式、并且点击这个数字还会自动拨号!默认开启
email:浏览器会识别邮箱并增加样式,点击调用系统默认邮件应用并给改地址发邮件!默认开启
address:address=yes就开启了点击地址直接跳转至地图的功能,默认开启


x5-orientation
QQ浏览器强制竖屏

<meta name="x5-orientation" content="portrait"/>

x5-fullscreen
QQ浏览器强制全屏

<meta name="x5-fullscreen" content="true"/>

x5-page-mode
QQ浏览器应用模式

<meta name="x5-page-mode" content="app"/>

X-UA-Compatible
IE的兼容模式:以IE的哪个版本去渲染页面(IE=8:以IE8的模式去渲染页面,IE=Edge:以最新版本的IE去渲染页面,当然这个最新指的是你系统装的最高版本的IE)

<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

renderer
这貌似是360浏览器专用,兼容360的利器啊,,360默认是用IE7去渲染页面的,不管你的系统装了多高版本的IE,这种行为真是业界毒瘤啊。

<meta name="renderer" content="webkit">//默认webkit内核
<meta name="renderer" content="ie-comp">//默认IE兼容模式
<meta name="renderer" content="ie-stand">//默认IE标准模式

常用写法:

设置页面不缓存

<!-- 禁止浏览器从本地计算机的缓存中访问页面内容 -->
<meta http-equiv=”pragma” content=”no-cache”>
<!-- 禁止浏览器缓存 -->
<meta http-equiv=”cache-control” content=”no-cache”>
<!--
 网页的缓存过期时间 
 比如<meta HTTP-EQUIV="expires" CONTENT="60">表示网页在60秒后过期
 <meta HTTP-EQUIV="expires" CONTENT="-1">这是特殊的用法,表示网页在任何时候都不能被Cache存储
-->
<meta http-equiv=”expires” content=”0″>

<!--页面重定向和刷新 -->
<meta http-equiv="refresh" content="0;url=" />

百度禁止转码

<!--  百度会自动对网页进行转码,这个标签是禁止百度的自动转码 -->

<meta http-equiv="Cache-Control" content="no-siteapp" />

SEO 优化部分

<!-- 页面关键词 keywords -->
<meta name="keywords" content="your keywords">
<!-- 页面描述内容 description -->
<meta name="description" content="your description">
<!-- 定义网页作者 author -->
<meta name="author" content="author,email address">
<!--
    定义网页搜索引擎索引方式,robotterms 是一组使用英文逗号「,」分割的值
    通常有如下几种取值
  all:文件将被检索,且页面上的链接可以被查询;
  none:文件将不被检索,且页面上的链接不可以被查询;
  index:文件将被检索;
  follow:页面上的链接可以被查询;
  noindex:文件将不被检索;
  nofollow:页面上的链接不可以被查询。
  -->
<meta name="robots" content="index,follow">

viewport

<!--  viewport主要是影响移动端页面布局的,例如: -->

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
    content 参数: 
    width: viewport 宽度(数值/device-width)
    height: viewport 高度(数值/device-height)
    initial-scale: 初始缩放比例
    maximum-scale: 最大缩放比例
    minimum-scale: 最小缩放比例
    user-scalable: 是否允许用户缩放(yes/no)
 -->

各浏览器平台:

IE

<!-- 优先使用最新的ie版本 -->
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- 是否开启cleartype显示效果 -->
<meta http-equiv="cleartype" content="on">
<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">


<!-- Pinned Site -->
<!-- IE 10 / Windows 8 -->
<meta name="msapplication-TileImage" content="pinned-tile-144.png">
<meta name="msapplication-TileColor" content="#009900">
<!-- IE 11 / Windows 9.1 -->
<meta name="msapplication-config" content="ieconfig.xml">

Chrome

<!-- 优先使用最新的chrome版本 -->
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<!-- 禁止自动翻译 -->
<meta name="google" value="notranslate">

360

<!-- 选择使用的浏览器解析内核 -->
<meta name="renderer" content="webkit|ie-comp|ie-stand">

UC手机浏览器

<!-- 将屏幕锁定在特定的方向 -->
<meta name="screen-orientation" content="landscape/portrait">
<!-- 全屏显示页面 -->
<meta name="full-screen" content="yes">
<!-- 强制图片显示,即使是"text mode" -->
<meta name="imagemode" content="force">
<!-- 应用模式,默认将全屏,禁止长按菜单,禁止手势,标准排版,强制图片显示。 -->
<meta name="browsermode" content="application">
<!-- 禁止夜间模式显示 -->
<meta name="nightmode" content="disable">
<!-- 使用适屏模式显示 -->
<meta name="layoutmode" content="fitscreen">
<!-- 当页面有太多文字时禁止缩放 -->
<meta name="wap-font-scale" content="no">

QQ手机浏览器

<!-- 锁定屏幕在特定方向 -->
<meta name="x5-orientation" content="landscape/portrait">
<!-- 全屏显示 -->
<meta name="x5-fullscreen" content="true">
<!-- 页面将以应用模式显示 -->
<meta name="x5-page-mode" content="app">

Apple iOS

<!-- Smart App Banner -->
<meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,
app-argument=SOME_TEXT">


<!-- 禁止自动探测并格式化手机号码 -->
<meta name="format-detection" content="telephone=no">
<!-- 忽略识别邮箱 -->
<meta content="email=no" name="format-detection" />

<!-- Add to Home Screen添加到主屏 -->
<!-- 是否启用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- 设置状态栏的背景颜色,只有在 “apple-mobile-web-app-capable” content=”yes” 时生效 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!-- 添加到主屏后的标题 -->
<meta name="apple-mobile-web-app-title" content="App Title">

Google Android

<meta name="theme-color" content="#E64545">
<!-- 添加到主屏 -->
<meta name="mobile-web-app-capable" content="yes">

App Links

<!-- iOS -->
<meta property="al:ios:url" content="applinks://docs">
<meta property="al:ios:app_store_id" content="12345">
<meta property="al:ios:app_name" content="App Links">
<!-- Android -->
<meta property="al:android:url" content="applinks://docs">
<meta property="al:android:app_name" content="App Links">
<meta property="al:android:package" content="org.applinks">
<!-- Web Fallback -->
<meta property="al:web:url" content="http://applinks.org/documentation">
<!-- More info: http://applinks.org/documentation/ -->

移动端

<!-- `width=device-width` 会导致 iPhone 5 添加到主屏后以 WebApp 全屏模式打开页面时出现黑边  -->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection"content="telephone=no, email=no" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<!-- 删除苹果默认的工具栏和菜单栏 -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- 设置苹果工具栏颜色 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 忽略页面中的数字识别为电话,忽略email识别 -->
<meta name="format-detection" content="telphone=no, email=no" />
<!-- 启用360浏览器的极速模式(webkit) -->
<meta name="renderer" content="webkit">
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 -->
<meta name="HandheldFriendly" content="true">
<!-- 微软的老式浏览器 -->
<meta name="MobileOptimized" content="320">
<!-- uc强制竖屏 -->
<meta name="screen-orientation" content="portrait">
<!-- QQ强制竖屏 -->
<meta name="x5-orientation" content="portrait">
<!-- UC强制全屏 -->
<meta name="full-screen" content="yes">
<!-- QQ强制全屏 -->
<meta name="x5-fullscreen" content="true">
<!-- UC应用模式 -->
<meta name="browsermode" content="application">
<!-- QQ应用模式 -->
<meta name="x5-page-mode" content="app">
<!-- windows phone 点击无高光 -->
<meta name="msapplication-tap-highlight" content="no">
上一篇 下一篇

猜你喜欢

热点阅读