网页头部各种meta标签功能大全
基础
<!-- H5标准声明,使用 HTML5 doctype,不区分大小写 --> <!DOCTYPE html> <!-- 标准的 lang 属性写法 --> <html lang="zh-cmn-Hans"> <!-- 声明文档使用的字符编码 --> <meta charset=’utf-8′> <!-- 优先使用 IE 最新版本和 Chrome进行渲染 --> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <!-- 页面描述 --> <meta name="description" content="不超过150个字符"/> <!-- 页面关键词 --> <meta name="keywords" content=""/> <!-- 网页作者 --> <meta name="author" content="name, email@gmail.com"/>
搜索引擎
<!-- 搜索引擎抓取 --> <meta name="robots" content="index,follow"/> <!-- 不让百度神马转码 --> <meta http-equiv="Cache-Control" content="no-siteapp" /> //神马 <meta http-equiv="Cache-Control" content="no-transform" /> //百度
HTML5屏幕适配
开发HTML5游戏中,我们常用的一些mata标签:
<!-- 为移动设备添加 viewport --> <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no" > <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
width: viewport 的宽度 (范围从 200 到 10,000 ,默认为 980 像素 )
height: viewport 的高度 (范围从 223 到 10,000 )
initial-scale: 初始的缩放比例 (范围从>0到 10 )
minimum-scale: 允许用户缩放到的最小比例
maximum-scale: 允许用户缩放到的最大比例
user-scalable: 用户是否可以手动缩放
下面是我们经常用到的一些标签,由于浏览器的差异,并不能百分百兼容。
<!-- 设置屏幕模式 --> <meta name="x5-page-mode" content="app" /> <!-- windows phone 点击无高光 --> <meta name="msapplication-tap-highlight" content="no">
360浏览器
<!-- 启用360浏览器的极速模式(webkit) --> <meta name="renderer" content="webkit">
QQ浏览器
<!-- QQ强制竖屏 --> <meta name="x5-orientation" content="portrait"> <!-- QQ强制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- QQ应用模式 --> <meta name="x5-page-mode" content="app">
UC浏览器
<!-- uc强制竖屏 --> <meta name="screen-orientation" content="portrait"> <!-- UC强制全屏 --> <meta name="full-screen" content="yes"> <!-- UC应用模式 --> <meta name="browsermode" content="application"> <!-- 缩放不出滚动条 --> <meta name="viewport" content="uc-fitscreen=no|yes"/> <!-- fitscreen简化页面处理,适合阅读省流量,standard和标准浏览器一致 --> <meta name="layoutmode" content="fitscreen|standard" /> <!-- 值设置为disable后,浏览器的夜间模式失效 --> <meta name="nightmode" content="enable|disable"/> <!-- 浏览器无图模式失效 --> <meta name="imagemode" content="force"/> <img src="" show="force"> //对单个图片进行设置,用这个。 <!-- 使用了application这种应用模式后,页面讲默认全屏,禁止长按菜单,禁止收拾,标准排版,以及强制图片显示 --> <meta name="browsermode" content="application"/>
apple手机
<!-- iOS 设备 begin --> <meta name="apple-mobile-web-app-title" content="标题"> <!-- 添加到主屏后的标题(iOS 6 新增) --> <meta name="apple-mobile-web-app-capable" content="yes"/> <!-- 是否启用 WebApp 全屏模式,删除苹果默认的工具栏和菜单栏 --> <meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否启用 WebApp 全屏模式,删除苹果默认的工具栏和菜单栏 --> <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
<!-- 如果 apple-mobile-web-app-capable 设置为 yes 了,那么在苹果机的safari上可以通过添加到主屏按钮将网站添加到主屏幕上。而设置相应 apple-touch-icon 标签,则添加到主屏上的图标就会使用我们指定的图片。 apple-touch-startup-image --> <link rel= "apple-touch-icon" sizes= "76x76" href= "touch-icon-ipad.png"> <!-- 基于 apple-mobile-web-app-capable 设置为 yes ,可以为WebApp设置一个类似NativeApp的启动画面。和 apple-touch-icon 不同, apple-mobile-web-app-capable 不支持sizes属性,要使用media来加载不同的启动画面。详细查询 大漠的文章 。 --> < link rel= "apple-touch-startup-image" href= "/startup.png">
<!-- iPhone --> <link href="apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image" /> <!-- iPhone Retina --> <link href="apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
<!-- 在web app应用下状态条(屏幕顶部条)的颜色; 默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明) 若值为“black-translucent”将会占据页面px位置,浮在页面上方(会覆盖页面20px高度–iphone4和itouch4的Retina屏幕为40px)。 --> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <!-- 添加智能 App 广告条 Smart App Banner(iOS 6+ Safari) --> <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
其他
<!-- 忽略页面中的数字识别为电话,忽略email、地图识别 --> <meta name="format-detection" content="telphone=no, email=no, adress=no"/> <!-- 可以用于设定网页的到期时间。一旦网页过期,必须到服务器上重新传输。 --> <meta http-equiv="expires"content="Fri,01Jan201618:18:18GMT"> <!-- 禁止浏览器从本地计算机的缓存中访问页面内容。 --> <meta http-equiv="Pragma" content="no-cache"> <!-- 自动刷新并指向新页面。 --> <meta http-equiv="Refresh" content="2;URL=http://www.jb51.net"> <!-- 如果网页过期,那么存盘的cookie将被删除。 --> <meta http-equiv="Set-Cookie"content="cookievalue=xxx;expires=Friday,12-Jan-200118:18:18GMT;path=/"> <!-- 强制页面在当前窗口以独立页面显示。 --> <meta http-equiv="Window-target" content="_blank"> <!– 添加 RSS 订阅 –> <link rel=”alternate” type=”application/rss+xml” title=”RSS” href=”/rss.xml”/> <!– 添加 favicon icon –> <link rel="shortcut icon" type="image/ico" href="/favicon.ico"/> <!-- 设置页面不缓存 --> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <!-- 手机百度搜索打开网页时,进行转码 --> <meta http-equiv="Cache-Control" content="no-siteapp" />
过气
<!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 --> <meta name="HandheldFriendly" content="true"> <!-- 微软的老式浏览器 --> <meta name="MobileOptimized" content="320">