当前位置:Gxlcms > html代码 > 常用HTMLmeta标签属性(网站兼容与优化需要)

常用HTMLmeta标签属性(网站兼容与优化需要)

时间:2021-07-01 10:21:17 帮助过:51人阅读

原文地址:http://segmentfault.com/blog/ciaocc/1190000002407912
作者:ciaocc
版权贵ciaocc所有,转载请注明版权。

概要

标签提供关于HTML文档的元数据。元数据不会显示在页面上,但是对于机器是可读的。它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 web 服务。 —— W3School

必要属性

属性 描述
content some text 定义与http-equiv或name属性相关的元信息

可选属性

属性 描述
http-equiv content-type / expire / refresh / set-cookie 把content属性关联到HTTP头部。
name author / description / keywords / generator / revised / others 把 content 属性关联到一个名称。
content some text 定义用于翻译 content 属性值的格式。


SEO优化

参考文档

页面关键词,每个网页应具有描述该网页内容的一组唯一的关键字。
使用人们可能会搜索,并准确描述网页上所提供信息的描述性和代表性关键字及短语。标记内容太短,则搜索引擎可能不会认为这些内容相关。另外标记不应超过 874 个字符。


代码如下:
<meta name="keywords" content="your tags" />

页面描述,每个网页都应有一个不超过 150 个字符且能准确反映网页内容的描述标签。

代码如下:
<meta name="description" content="150 words" />

搜索引擎索引方式,robotterms是一组使用逗号(,)分割的值,通常有如下几种取值:none,noindex,nofollow,all,index和follow。确保正确使用nofollow和noindex属性值。


代码如下:

<meta name="robots" content="index,follow" />
<!--
all:文件将被检索,且页面上的链接可以被查询;
none:文件将不被检索,且页面上的链接不可以被查询;
index:文件将被检索;
follow:页面上的链接可以被查询;
noindex:文件将不被检索;
nofollow:页面上的链接不可以被查询。
-->

页面重定向和刷新:content内的数字代表时间(秒),既多少时间后刷新。如果加url,则会重定向到指定网页(搜索引擎能够自动检测,也很容易被引擎视作误导而受到惩罚)。


代码如下:

<meta http-equiv="refresh" content="0;url=" />

其他


代码如下:

<meta name="author" content="author name" /> <!-- 定义网页作者 -->
<meta name="google" content="index,follow" />
<meta name="googlebot" content="index,follow" />
<meta name="verify" content="index,follow" />


移动设备

viewport:能优化移动浏览器的显示。如果不是响应式网站,不要使用initial-scale或者禁用缩放。
大部分4.7-5寸设备的viewport宽设为360px;5.5寸设备设为400px;iphone6设为375px;ipone6 plus设为414px。


代码如下:

<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
<!-- `width=device-width` 会导致 iPhone 5 添加到主屏后以 WebApp 全屏模式打开页面时出现黑边 -->

1.width:宽度(数值 / device-width)(范围从200 到10,000,默认为980 像素)
2.height:高度(数值 / device-height)(范围从223 到10,000)
3.initial-scale:初始的缩放比例 (范围从>0 到10)
4.minimum-scale:允许用户缩放到的最小比例
5.maximum-scale:允许用户缩放到的最大比例
6.user-scalable:用户是否可以手动缩 (no,yes)
7.minimal-ui:可以在页面加载时最小化上下状态栏。(已弃用)
注意,很多人使用initial-scale=1到非响应式网站上,这会让网站以100%宽度渲染,用户需要手动移动页面或者缩放。如果和initial-scale=1同时使用user-scalable=no或maximum-scale=1,则用户将不能放大/缩小网页来看到全部的内容。

WebApp全屏模式:伪装app,离线应用。


代码如下:

<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 启用 WebApp 全屏模式 -->

隐藏状态栏/设置状态栏颜色:只有在开启WebApp全屏模式时才生效。content的值为default | black | black-translucent 。


代码如下:

<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

添加到主屏后的标题


代码如下:
<meta name="apple-mobile-web-app-title" content="标题">

忽略数字自动识别为电话号码

代码如下:
<meta content="telephone=no" name="format-detection" />

忽略识别邮箱


代码如下:
<meta content="email=no" name="format-detection" />

添加智能 App 广告条 Smart App Banner:告诉浏览器这个网站对应的app,并在页面上显示下载banner(如下图)。参考文档


代码如下:
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">

其他 参考文档

  1. <div style="display:none">
  2. <div class="login-box" id="login-dialog">
  3. <div class="login-top"><a class="current" rel="nofollow" id="login1" onclick="setTab('login',1,2);">登录</a></div>
  4. <div class="login-form" id="nav-signin">
  5. <!-- <div class="login-ico"><a rel="nofollow" class="qq" id="qqlogin" target="_blank" href="/user-center-qqlogin.html"> QQ </a></div> -->
  6. <div class="login-box-form" id="con_login_1">
  7. <form id="loginform" action="/user-center-login.html" method="post" onsubmit="return false;">
  8. <p class="int-text">
  9. <input class="email" id="username" name="username" type="text" value="用户名或Email" onfocus="if(this.value=='用户名或Email'){this.value='';}" onblur="if(this.value==''){this.value='用户名或Email';};"></p>
  10. <p class="int-text">
  11. <input class="password1" type="password" id="password" name="password" value="******" onblur="if(this.value=='') this.value='******';" onfocus="if(this.value=='******') this.value='';">
  12. </p>
  13. <p class="int-info">
  14. <label class="ui-label"> </label>
  15. <label for="agreement" class="ui-label-checkbox">
  16. <input type="checkbox" value="" name="cookietime" id="cookietime" checked="checked">
  17. <input type="hidden" name="notforward" id="notforward" value="1">
  18. <input type="hidden" name="dosubmit" id="dosubmit" value="1">记住我的登录 </label>
  19. <a rel="nofollow" class="aright" href="/user-center-forgetpwd.html" target="_blank"> 忘记密码? </a></p>
  20. <p class="int-btn"><a rel="nofollow" id="loginbt" class="loginbtn"><span>登录</span></a></p>
  21. </form>
  22. </div>
  23. <form id="regform" action="/user-center-reg.html" method="post">
  24. <div class="login-reg" style="display: none;" id="con_login_2">
  25. <input type="hidden" name="t" id="t">
  26. <p class="int-text">
  27. <input id="email" name="email" type="text" value="Email" onfocus="if(this.value=='Email'){this.value='';}" onblur="if(this.value==''){this.value='Email';};"></p>
  28. <p class="int-text">
  29. <input id="uname" name="username" type="text" value="用户名或昵称" onfocus="if(this.value=='用户名或昵称'){this.value='';}" onblur="if(this.value==''){this.value='用户名或昵称';};"></p>
  30. <p class="int-text">
  31. <input type="password" id="pwd" name="password" value="******" onblur="if(this.value=='') this.value='******';" onfocus="if(this.value=='******') this.value='';"> </p>
  32. <p class="int-text1"><span class="inputbox">
  33. <input id="validate" name="validate" type="text" value="验证码" onfocus="if(this.value=='验证码'){this.value='';}" onblur="if(this.value==''){this.value='验证码';};">
  34. </span><span class="yzm-img"><img src="/user-checkcode-index" alt="看不清楚换一张" id="indexlogin"></span></p>
  35. <p class="int-info">
  36. <label>
  37. <input value="" name="agreement" id="agreement" checked="checked" type="checkbox">
  38. 我已阅读<a rel="nofollow" href="/user-center-agreement.html">用户协议</a>及<a rel="nofollow" href="/user-center-agreement.html">版权声明</a></label>
  39. </p>
  40. <p class="int-btn"><input type="hidden" name="dosubmit">
  41. <a rel="nofollow" class="loginbtn" id="register"><span>注册</span></a></p>
  42. </div>
  43. </form>
  44. </div>
  45. </div>
  46. </div>