<meta>详解
一、name属性
主要用于描述网页,对应属性值content的内容是便于搜索引擎查找/分类信息用的。
1、Keywords(关键字):告诉搜索引擎你网页的关键字是什么。
2、description:告诉搜索引擎网站主要内容
网站描述为自然语言而不是罗列关键字;
准确描述核心内容,通常为希望搜索引擎在检索结果中展示的摘要信息,并且与网页标题与主体有高度相关性;
描述文字不必太多(通常不超过100个字符);
3、robots(机器人导向):哪些页面需要抓取,哪些不需要。
content参数 :
1、all - 文件将被检索,且页面连接可被查询、
2、none - 文件不被检索,且连接不被查询、
3、index - 文件将被检索、
4、noindex - 文件不被检索,但页面链接可被查询、
5、follow - 网页链接可被查询、
6、nofollow - 文件被检索,但页面链接不可被查询。
4、author:网站版权作者信息
5、generator:网站采用什么软件制作
6、copyright:网站版权信息
7、revisit-after:网站重访【content='7 days' 代表7天】
<meta name="keywords" content="识别,核验" /> <meta name="description" content="本页面是关于识别、核验、产品的介绍。"> <meta name="robots" content="none" /> <meta name="author" content="sherry,sherry@**.com" />
<!--
移动端应用
width:控制 viewport 的大小,可以指定的一个值,如果 600,或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)。
height:和 width 相对应,指定高度。
initial-scale:初始缩放比例,也即是当页面第一次 load 的时候缩放比例。
maximum-scale:允许用户缩放到的最大比例。
minimum-scale:允许用户缩放到的最小比例。
user-scalable:是否允许用户手动缩放【no 不允许、yes 允许】
-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!--设置浏览器的兼容模式版本。表示如果在IE浏览器下则使用最新的标准,渲染当前文档。-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1
">
<meta http-equiv = "X-UA-Compatible" content = "IE=edge" />
二、http-equiv
属性,相当于http的文件头,它可以像浏览器传回一些有用信息,以帮助正确的显示页面
1、expires(期限):设定网页到期时间。到期后必须到服务器重新传输【GMT时间格式】。
2、pragma(cache模式):禁止浏览器从本地计算机缓存中访问页面【设定后访问者将无法脱机浏览】
3、Refresh(刷新):自动刷新并指向新页面【content中秒数是指 停留几秒后自动刷新到URL网址】
4、Set-Cookie(cookie设定):网站过期云盘cookie将被删除
5、Window-targrt(显示窗口的设定):强制页面在当前窗口以独立页面显示【防止他人在框架里调用】
6、content-Type:设置页面使用的字符集【http头部协议】
content里charset参数:
1、GB2312 - 网站编码简体中文
2、BIG5 - 繁体中文
3、iso-2022-jp - 日文
4、ks_c_5601 - 韩文
5、ISO-8859-1 - 英文
6、UTF-8 - 世界通用语言编码
7、Content-Language:显示语言设定
8、imagetoolbar:指定是否显示图片工具栏【false不显示、true显示】
9、Content-Script-Type:W3C网页规范,指网站脚本类型
<meta http-equiv="expires" content="Fri,12 Jan 2022 22:30:30 GMT" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="Refresh" content="秒数;URL=http://www.baidu.com"> <meta http-equiv="Set-Cookie" content="cookievalue=XXX;expires=Fridy,15-Apr-2021 12:03:07 GMT; path=/"> <meta http-equiv="Window-targrt" content="_top"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="imagetoolbar" content="false"> <meta http-equiv="Content-Script-Type" content="text/javascript">
<!--百度禁止转码:百度自动对网页进行转码 -->
<meta http-equiv="pragma" content="no-cache">
三、常用功能:
1、帮助页面被各大搜索引擎登录、提高页面点击率。
2、定义页面使用语言
3、自动刷新并指向新页面【无人操作的情况下,能自动在指定时间去访问指定页面】
4、实现效果:进入或离开页面时实现动画效果【此网页不能是frame】
RevealTrans 动态滤镜:
1、duration:表示滤镜特效的持续时间(单位:秒)
2、transition:滤镜类型。(取值0-23)
0 - 矩形缩小、1 - 矩形放大、2 - 圆形缩小、3 - 圆形放大、
4 - 下到上刷新、5 - 上到下刷新、6 - 左到右刷新、7 - 右到左刷新、
8 - 竖百叶窗、9 - 横百叶窗、10 - 错位横百叶窗、11 - 错位竖百叶窗、
12 - 点扩散、13 - 左右到中间刷新、14 - 中间到左右刷新、
15 - 中间到上下、16 - 上下到中间、17 - 右下到左上、18 - 右上到左下、19 - 左上到右下、20 - 左下到右上、
21 - 横条、22 - 竖条、23 - 以上22种随机
<meta http-equiv="Page-Enter" content="revealTrans(duration=5.0,transition=20)"> <meta http-equiv="Page-Exit" content="revealTrans(duration=5.0,transition=20)">
5、网页定级评价、控制页面缓冲、控制网页显示窗口
四、其他
Base:插入网站基链接属性【网页上所有相对路径在链接时都将加上此路径】
_blank 新窗口打开
_parent 当前窗口父级窗口打开
_self 链接文件在当前窗口(帧)中打开
_top 全屏显示
<Base href="http://www.practice/" target="_blank">
五、SEO优化 常用
<!-- 页面标题<title>标签(head 头部必须) --> <title>your title</title> <!-- 页面关键词 keywords --> <meta name="keywords" content="your keywords"> <!-- 页面描述内容 description --> <meta name="description" content="your description"> <!-- 定义网页作者 author --> <meta name="author" content="author,email address"> <!-- 定义网页搜索引擎索引方式,robotterms 是一组使用英文逗号「,」分割的值,通常有如下几种取值:none,noindex,nofollow,all,index和follow。 --> <meta name="robots" content="index,follow">
六、移动端
<!--
移动端应用
width:控制 viewport 的大小,可以指定的一个值,如果 600,或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)。
height:和 width 相对应,指定高度。
initial-scale:初始缩放比例,也即是当页面第一次 load 的时候缩放比例。
maximum-scale:允许用户缩放到的最大比例。
minimum-scale:允许用户缩放到的最小比例。
user-scalable:是否允许用户手动缩放【no 不允许、yes 允许、0不缩放】
注意:据说HTC G7自身系统浏览器不支持这一条规则,能对页面进行放大,一旦放大导致页面布局错乱。解决方法:定义页面的最小宽度 min-width,body{min-width: 300px;}
-->
<meta name="viewport" content="width=device-width;initial-scale=1.0; maximum-scale=1.0; user-scalable=0;” />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!-- telephone=no 就禁止了把数字转化为拨号链接! 默认yes开启转换
设备浏览网页时对数字不启用电话功能(不同设备解释不同,itouch点击数字为存入联系人,iphone为拨打电话),忽略将页面中的数字识别为电话号码。
--> <meta name="format-detection" content="telephone=no,email=no"/> <!--删除默认的苹果工具栏和菜单栏--> <meta name="apple-mobile-web-app-capable" content="yes" /> <!--ios系统的私有标签 控制状态栏显示样式
默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明)
若值为“black-translucent”将会占据页面px位置,浮在页面上方(会覆盖页面20px高度–iphone4和itouch4的Retina屏幕为40px)。
--> <meta name="apple-mobile-web-app-status-bar-style" content="default" />
<!--允许全屏模式浏览,开启对Web Aapp程序的支持-->
<meta name="apple-mobile-web-app-capable" content="yes" />
<!--iOS 7.1的Safari为meta标签新增minimal-ui属性,在网页加载时隐藏地址栏与导航栏。-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
<!--添加到主屏后的标题(iOS 6 新增)-->
<meta name="apple-mobile-web-app-title" content="标题" />
<!--添加智能 App 广告条 Smart App Banner(iOS 6+ Safari)-->
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL" />
iOS 图标设置
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png"/> <!-- iPhone 和 iTouch,默认 57x57 像素,必须有 --> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png"/> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以没有,但推荐有 --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png"/> <!-- Retina iPad,144x144 像素,可以没有,但推荐有 -->
iOS 启动画面
<link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png"/> <!-- iPad 竖屏 768 x 1004(标准分辨率) --> <link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png"/> <!-- iPad 竖屏 1536x2008(Retina) --> <link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png"/> <!-- iPad 横屏 1024x748(标准分辨率) --> <link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png"/> <!-- iPad 横屏 2048x1496(Retina) --> <link rel="apple-touch-startup-image" href="/splash-screen-320x480.png"/> <!-- iPhone/iPod Touch 竖屏 320x480 (标准分辨率) --> <link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png"/> <!-- iPhone/iPod Touch 竖屏 640x960 (Retina) --> <link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png"/> <!-- iPhone 5/iPod Touch 5 竖屏 640x1136 (Retina) -->
一些特殊浏览器的设置:
QQ浏览器相关设置: <meta name="x5-orientation" content="portrait"> <!-- QQ强制竖屏 --> <meta name="x5-fullscreen" content="true"> <!-- QQ强制全屏 --> <meta name="x5-page-mode" content="app"> <!-- QQ应用模式 --> UC浏览器相关设置: <!-- UC强制竖屏 --> <meta name="screen-orientation" content="portrait"> <!-- UC强制全屏 --> <meta name="full-screen" content="yes"> <!-- UC应用模式 --> <meta name="browsermode" content="application"> 360浏览器: <meta name="renderer" content="webkit"> <!-- 启用360浏览器的极速模式(webkit) --> windows相关设备: <meta name="msapplication-tap-highlight" content="no"> <!-- windows phone 点击无高光 --> <meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁贴颜色 --> <meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁贴图标 --> <link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml"/> <!-- 添加 RSS 订阅 --> <link rel="shortcut icon" type="image/ico" href="/favicon.ico"/> <!-- 添加 favicon icon --> 其他设备设置: <meta name="HandheldFriendly" content="true"> <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 --> 最后讲讲常用的老浏览器霸主IE <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"> <!-- 避免IE使用兼容模式 --> X-UA-Compatible是神马? X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中使用。可以在微软官方文档获取更多介绍。 为什么要用X-UA-Compatible? 在IE8刚推出的时候,很多网页由于重构的问题,无法适应较高级的浏览器,所以使用X-UA-Compatible标签强制IE8采用低版本方式渲染。 使用下面这段代码后,开发者无需考虑网页是否兼容IE8浏览器,只要确保网页在IE6、IE7下的表现就可以了。 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 使用下面这段代码使用的是Edge 。模式Edge 模式告诉 IE 以最高级模式渲染文档,也就是任何 IE 版本都以当前版本所支持的最高级标准模式渲染,避免版本升级造成的影响。简单的说,就是什么版本 IE 就用什么版本的标准模式渲染。 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 使用以下代码强制 IE 使用 Chrome Frame 渲染 <meta http-equiv="X-UA-Compatible" content="chrome=1"> 最佳的兼容模式方案: <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> ps:为防止失效,X-UA-Compatible最好紧跟在head之后,之前不要有任何不标准的标签。
下面是配置大全
<link rel="dns-prefetch" href="//www.zhoulujun.cn"> <!--设置dns缓存--> <meta name="applicable-device" content="pc,mobile"> <!--设置支持终端--> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <!--设置屏幕缩放--> <meta http-equiv="content-Type" content="text/html;charset=gb2312"> <!--设定页面使用的字符集。--> <meta http-equiv="Content-Language" content="zh-cn"/> <!--设定显示语言--> <meta name="keywords" content="周陆军"/> <!--设置网页关键词,SEO--> <meta name="description" content="周陆军网站"/> <!--设置网页内容描述,SEO--> <meta name="author" content="周陆军"/> <!--设置网页作者--> <meta name="generator" content="intellij"/> <!--说明网站的采用的什么软件制作--> <meta name='Copyright' content='zhoulujun'> <!--说明网站版权信息--> <meta name="apple-mobile-web-app-title" content="周陆军的个人网站"> <!-- 添加到主屏后的标题(iOS 6 新增) --> <meta name="apple-mobile-web-app-capable" content="yes"/> <!-- 是否启用 WebApp 全屏模式,删除苹果默认的工具栏和菜单栏 --> <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=http://www.zhoulujun.cn"> <!-- 添加智能 App 广告条 Smart App Banner(iOS 6+ Safari) --> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <!-- 设置苹果工具栏颜色 -->
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png"/> <!-- iPhone 和 iTouch,默认 57x57 像素,必须有 --> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png"/> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以没有,但推荐有 --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png"/> <!-- Retina iPad,144x144 像素,可以没有,但推荐有 --> <meta name="x5-orientation" content="portrait"> <!-- QQ强制竖屏 --> <meta name="x5-fullscreen" content="true"> <!-- QQ强制全屏 --> <meta name="x5-page-mode" content="app"> <!-- QQ应用模式 --> <!-- UC强制竖屏 --> <meta name="screen-orientation" content="portrait"> <!-- UC强制全屏 --> <meta name="full-screen" content="yes"> <!-- UC应用模式 --> <meta name="browsermode" content="application"> <meta name="renderer" content="webkit"> <!-- 启用360浏览器的极速模式(webkit) --> <meta name="msapplication-tap-highlight" content="no"> <!-- windows phone 点击无高光 --> <meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁贴颜色 --> <meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁贴图标 --> <link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml"/> <!-- 添加 RSS 订阅 --> <link rel="shortcut icon" type="image/ico" href="/favicon.ico"/> <!-- 添加 favicon icon --> <meta name="HandheldFriendly" content="true"> <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 -->
其他:
1.如何去除iOS和Android中的输入URL的控件条
setTimeout(scrollTo,0,0,0) 【这句代码必须放在window.onload里才能够正常的工作,而且你的当前文档的内容高度必须是高于窗口的高度时,这句代码才能有效的执行】
2.禁止用户旋转设备【移动端做不到】
3.关闭iOS中键盘自动大写
iOS虚拟键盘弹出时,默认键盘是开启首字母大写的功能的,根据某些业务场景,可能我们需要关闭这个功能,移动版本webkit为 input元素提供了autocapitalize属性,通过指定autocapitalize=”off”来关闭键盘默认首字母大写。
4.iOS中如何彻底禁止用户在新窗口打开页面
a标签的target=”_self“来指定用户在新窗口打开,或者target属性保持空
但 iOS在这个链接的上方长按3秒钟后,iOS会弹出一个列表按钮,用户通过这些按钮仍然可以在新窗口打开页面,这样的话,开发者指定的 target属性就失效了,但是可以通过指定当前元素的-webkit-touch-callout样式属性为none来禁止iOS弹出这些按钮。
这个技 巧仅适用iOS对于Android平台则无效。
5.iOS中如何禁止用户保存图片\复制图片
为一个img指定-webkit-touch-callout为none会禁止设备弹出列表按钮,这样用户就无法保存\复制你的图片了。
6.iOS中如何禁止用户选中文字
文字标签的-webkit-user-select属性为none便可以禁止iOS用户选中文字。
7.iOS中如何获取滚动条的值
浏览器想要获取滚动条的值是通过document.scrollTop和document.scrollLeft得到的,但在iOS中你会发现这两 个属性是未定义的,Android中可以正常获取,那么iOS我们通过window.scrollY和window.scrollX可以得到当前窗口的y轴和x轴滚动条的值。
参考:https://zhuanlan.zhihu.com/p/28944617;
https://zhuanlan.zhihu.com/p/42151227;
https://www.jianshu.com/p/669909fab18a?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation;