首頁  >  文章  >  web前端  >  html常用meta整理

html常用meta整理

伊谢尔伦
伊谢尔伦原創
2016-11-23 11:28:111598瀏覽

  元素

  概要

標籤提供關於HTML文件的元資料。元資料不會顯示在頁面上,但是對於機器是可讀的。它可用於瀏覽器(如何顯示內容或重新載入頁面),搜尋引擎(關鍵字),或其他 web 服務。

  必要屬性

屬性               值         

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 全屏模式打开页面时出现黑边  -->

width:寬度(數值/ device-width)(範圍從200 到10,000,預設為980 像素)

height:高度(數值/ device-height)(範圍從223 到

height:高度(數值/ device-height)(範圍從223 到

初始的縮放比例(範圍從>0 到10)


minimum-scale:允許用戶縮放到的最小比例

maximum-scale:允許用戶縮放到的最大比例

user-scalable:用戶是否可以手動縮放( no,yes)

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" />

BanAppner 廣告SmartBmart:appSmart App在頁面上顯示下載banner(如下圖)。參考文件

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
html常用meta整理

其他 參考文件

<!-- 针对手持设备优化,主要是针对一些老的不识别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">

  网页相关

申明编码

<meta charset=&#39;utf-8&#39; />

优先使用 IE 最新版本和 Chrome

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 关于X-UA-Compatible -->
<meta http-equiv="X-UA-Compatible" content="IE=6" ><!-- 使用IE6 -->
<meta http-equiv="X-UA-Compatible" content="IE=7" ><!-- 使用IE7 -->
<meta http-equiv="X-UA-Compatible" content="IE=8" ><!-- 使用IE8 -->

浏览器内核控制:国内浏览器很多都是双内核(webkit和Trident),webkit内核高速浏览,IE内核兼容网页和旧版网站。而添加meta标签的网站可以控制浏览器选择何种内核渲染。参考文档

<meta name="renderer" content="webkit|ie-comp|ie-stand">

  国内双核浏览器默认内核模式如下:

  1. 搜狗高速浏览器、QQ浏览器:IE内核(兼容模式)

  2. 360极速浏览器、遨游浏览器:Webkit内核(极速模式)

禁止浏览器从本地计算机的缓存中访问页面内容:这样设定,访问者将无法脱机浏览。

<meta http-equiv="Pragma" content="no-cache">

Windows 8

<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁贴颜色 -->
<meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁贴图标 -->

站点适配:主要用于PC-手机页的对应关系。

<meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url">
<!--
[wml|xhtml|html5]根据手机页的协议语言,选择其中一种;
url="url" 后者代表当前PC页所对应的手机页URL,两者必须是一一对应关系。
 -->

转码申明:用百度打开网页可能会对其进行转码(比如贴广告),避免转码可添加如下meta

<meta http-equiv="Cache-Control" content="no-siteapp" />
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn