[HTML5]移动端web页面开发常用的头部标签设置

HTML5移动端web页面开发常用的头部标签设置

移动端web页面开发常用的头部标签设置

在移动端web页面开发中,我们常需要设置各种头部标签以帮助浏览器更好的解析页面,将页面完美呈现,这里列出了工作中常用的各种头部标签,以备查询。

viewport

html 复制代码
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">

initial-scale属性控制页面最初加载时的缩放等级。maximum-scale、minimum-scale及user-scalable属性控制允许用户以怎样的方式放大或缩小页面。
使用目的:阻止页面缩放
Safari 无效,其他均能阻止页面缩放
safari可以使用以下方法

html 复制代码
window.onload = function() {
  document.addEventListener('touchstart', function(event) {
    if (event.touches.length > 1) {//多触点
      event.preventDefault();//阻止默认缩放
    }
  })
  var lastTouchEnd = 0;
  document.addEventListener('touchend', function(event) {
    var now = (new Date()).getTime();
    if (now - lastTouchEnd <= 300) {
      event.preventDefault(); //阻止双击放大
    }
    lastTouchEnd = now;
  }, false)
}

ios meta

html 复制代码
<meta name="apple-mobile-web-app-capable" content="yes"/>

启用 WebApp 全屏模式,删除苹果默认的工具栏和菜单栏

html 复制代码
<meta name="apple-mobile-web-app-title" content="标题">

设置添加到主屏后的标题

html 复制代码
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>

在web app应用下状态条(屏幕顶部条)的颜色,default(白色)black(黑色) black-translucent(灰色半透明)

若值为"black-translucent"将会占据页面位置(会覆盖页面20px高度--iphone4和itouch4的Retina屏幕为40px)。

html 复制代码
<meta name="format-detection" content="telphone=no, email=no"/>

忽略页面中的数字识别为电话,忽略email识别

iOS 添加到主屏图标

html 复制代码
<link rel="apple-touch-icon" href="apple-touch-icon.png">

ios7以前系统默认会对图标添加特效(圆角及高光),如果不希望系统添加特效,则可以用apple-touch-icon-precomposed.png代替apple-touch-icon.png

html 复制代码
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-57x57-precomposed.png"/>

iPhone 和 iTouch,默认 57x57 像素,必须有

html 复制代码
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-114x114-precomposed.png"/>

Retina iPhone 和 Retina iTouch,114x114 像素,可以没有,但推荐有
图标使用的优先级如下:

  • 如果没有跟相应设备推荐尺寸一致的图标,会优先使用比推荐尺寸大,但最接近推荐尺寸的图标。
  • 如果没有比推荐尺寸大的图标,会优先选择最接近推荐尺寸的图标。

iOS 启动画面
iPhone

html 复制代码
<link rel="apple-touch-startup-image" media="(device-width: 320px)" href="apple-touch-startup-image-320x460.png"   /> 

iPhone Retina

html 复制代码
<link href="apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" /> 

iPhone 5

html 复制代码
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="apple-touch-startup-image-640x1096.png"> 

iPad portrait

html 复制代码
<link href="apple-touch-startup-image-768x1004.png" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image" /> 

iPad landscape

html 复制代码
<link href="apple-touch-startup-image-748x1024.png" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image" /> 

iPad Retina portrait

html 复制代码
<link href="apple-touch-startup-image-1536x2008.png" media="(device-width: 1536px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" /> 

iPad Retina landscape

html 复制代码
<link href="apple-touch-startup-image-1496x2048.png"media="(device-width: 1536px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)"rel="apple-touch-startup-image" />

其他

html 复制代码
<link rel="dns-prefetch" href="//api.m.taobao.com">

DNS预解析

html 复制代码
<link rel="shortcut icon" type="image/ico" href="/favicon.ico"/>

添加 favicon icon

html 复制代码
<meta name="renderer" content="webkit">

启用360浏览器的极速模式(webkit)

html 复制代码
<meta http-equiv="X-UA-Compatible" content="IE=edge">

IE使用现有最高版本

html 复制代码
<meta http-equiv="Cache-Control" content="no-siteapp" />

不让百度转码

html 复制代码
<meta name="x5-orientation" content="portrait">

QQ强制竖屏

html 复制代码
<meta name="x5-fullscreen" content="true">

QQ强制全屏

html 复制代码
<meta name="x5-page-mode" content="app">

QQ应用模式

html 复制代码
<meta name="screen-orientation" content="portrait">

UC强制竖屏

html 复制代码
<meta name="full-screen" content="yes">

UC强制全屏

html 复制代码
<meta name="browsermode" content="application">

UC应用模式

html 复制代码
<meta name="msapplication-tap-highlight" content="no">

windows phone 点击无高光

html 复制代码
<meta name="robots" content="index,follow"/>

搜索引擎抓取

说明:

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

具体参数如下:

信息参数为all:文件将被检索,且页面上的链接可以被查询;

信息参数为none:文件将不被检索,且页面上的链接不可以被查询;

信息参数为index:文件将被检索;

信息参数为follow:页面上的链接可以被查询;

信息参数为noindex:文件将不被检索,但页面上的链接可以被查询;

信息参数为nofollow:文件将被检索,但页面上的链接不可以被查询;

相关推荐
变与不变8068 小时前
jQuery怎么使用
前端·javascript
神膘护体小月半8 小时前
flex 布局的 order 属性
前端·css
paopaokaka_luck8 小时前
流浪动物救助与收养系统(DeepSeek AI对话、 ECharts多维分析、救助流程衔接、领养与回访衔接、 捐赠确认与公示、志愿者协作)
java·前端·javascript·人工智能·mysql·echarts·推荐算法
仰望.8 小时前
vue 表格组件 vxe-table 树表格懒加载支持拖拽排序的详细用法
前端·javascript·vue.js·vxe-table
前端 贾公子8 小时前
vite-plugin-uni-manifest 升级指南
前端
小码哥_常9 小时前
iPhone 用户传了张 HEIC,我的前端崩了
前端
小码哥_常9 小时前
你发的原图可能暴露你家地址——聊聊图片 EXIF 隐私
前端
java1234_小锋9 小时前
【技术专题】CSS3 网页技术 - CSS3 优先级
前端·css·css3
鸿蒙开发10 小时前
共享 Schema 与 SchemaFactory
前端·后端·harmonyos
屏什么录10 小时前
录屏超过两小时就卡顿崩盘?从参数调优到代码实现,一文彻底搞定长时间录屏
前端·音视频开发