< meta > 元素
概要
meta標(biāo)簽提供關(guān)于HTML文檔的元數(shù)據(jù)蝗拿。元數(shù)據(jù)不會(huì)顯示在頁面上榕订,但是對(duì)于機(jī)器是可讀的析显。它可用于瀏覽器(如何顯示內(nèi)容或重新加載頁面),搜索引擎(關(guān)鍵詞)肚豺,或其他 web 服務(wù)溃斋。
-
頁面關(guān)鍵詞,每個(gè)網(wǎng)頁應(yīng)具有描述該網(wǎng)頁內(nèi)容的一組唯一的關(guān)鍵字吸申。
使用人們可能會(huì)搜索梗劫,并準(zhǔn)確描述網(wǎng)頁上所提供信息的描述性和代表性關(guān)鍵字及短語。標(biāo)記內(nèi)容太短截碴,則搜索引擎可能不會(huì)認(rèn)為這些內(nèi)容相關(guān)梳侨。另外標(biāo)記不應(yīng)超過 874 個(gè)字符。
<pre><meta name="keywords" content="your tags" /></pre> 頁面描述日丹,每個(gè)網(wǎng)頁都應(yīng)有一個(gè)不超過 150 個(gè)字符且能準(zhǔn)確反映網(wǎng)頁內(nèi)容的描述標(biāo)簽走哺。
<pre><meta name="description" content="150 words" /></pre>搜索引擎索引方式,robotterms是一組使用逗號(hào)(,)分割的值哲虾,通常有如下幾種取值:none丙躏,noindex齐帚,nofollow,all彼哼,index和follow。確保正確使用nofollow和noindex屬性值湘今。
<pre>
<meta name="robots" content="index,follow" />
</pre>
頁面重定向和刷新:content內(nèi)的數(shù)字代表時(shí)間(秒)敢朱,既多少時(shí)間后刷新。如果加url,則會(huì)重定向到指定網(wǎng)頁(搜索引擎能夠自動(dòng)檢測摩瞎,也很容易被引擎視作誤導(dǎo)而受到懲罰)拴签。
<pre><meta http-equiv="refresh" content="0;url=" /></pre>其他
<pre>
<meta name="author" content="author name" />
<meta name="google" content="index,follow" />
<meta name="googlebot" content="index,follow" />
<meta name="verify" content="index,follow" />
</pre>
移動(dòng)設(shè)備
-
viewport:能優(yōu)化移動(dòng)瀏覽器的顯示。如果不是響應(yīng)式網(wǎng)站旗们,不要使用initial-scale或者禁用縮放蚓哩。
大部分4.7-5寸設(shè)備的viewport寬設(shè)為360px;5.5寸設(shè)備設(shè)為400px上渴;iphone6設(shè)為375px岸梨;ipone6 plus設(shè)為414px。
<pre>
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
</pre>
- width:寬度(數(shù)值 / device-width)(范圍從200 到10,000稠氮,默認(rèn)為980 像素)
- height:高度(數(shù)值 / device-height)(范圍從223 到10,000)
- initial-scale:初始的縮放比例 (范圍從>0 到10)
- minimum-scale:允許用戶縮放到的最小比例
- maximum-scale:允許用戶縮放到的最大比例
- user-scalable:用戶是否可以手動(dòng)縮 (no,yes)7. minimal-ui:可以在頁面加載時(shí)最小化上下狀態(tài)欄曹阔。(已棄用)
注意,很多人使用initial-scale=1到非響應(yīng)式網(wǎng)站上隔披,這會(huì)讓網(wǎng)站以100%寬度渲染赃份,用戶需要手動(dòng)移動(dòng)頁面或者縮放。如果和initial-scale=1同時(shí)使用user-scalable=no或maximum-scale=1奢米,則用戶將不能放大/縮小網(wǎng)頁來看到全部的內(nèi)容抓韩。
WebApp全屏模式:偽裝app,離線應(yīng)用鬓长。
<pre>
<meta name="apple-mobile-web-app-capable" content="yes" />
</pre>隱藏狀態(tài)欄/設(shè)置狀態(tài)欄顏色:只有在開啟WebApp全屏模式時(shí)才生效谒拴。content的值為default | black | black-translucent 。
<pre><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /></pre>添加到主屏后的標(biāo)題
<pre><meta name="apple-mobile-web-app-title" content="標(biāo)題"></pre>
忽略數(shù)字自動(dòng)識(shí)別為電話號(hào)碼
<pre><meta content="telephone=no" name="format-detection" /></pre>忽略識(shí)別郵箱
<pre><meta content="email=no" name="format-detection" /></pre>添加智能 App 廣告條 Smart App Banner:告訴瀏覽器這個(gè)網(wǎng)站對(duì)應(yīng)的app痢士,并在頁面上顯示下載banner(如下圖)彪薛。參考文檔
<pre>
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
</pre>
![](./IMG_3701.jpg)
-
其他 參考文檔
<pre>
<meta name="HandheldFriendly" content="true">
<meta name="MobileOptimized" content="320">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<meta name="browsermode" content="application">
<meta name="x5-page-mode" content="app">
<meta name="msapplication-tap-highlight" content="no">
</pre>
網(wǎng)頁相關(guān)
申明編碼
<pre><meta charset='utf-8' /></pre>優(yōu)先使用 IE 最新版本和 Chrome
<pre>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="X-UA-Compatible" content="IE=6" >
<meta http-equiv="X-UA-Compatible" content="IE=7" >
<meta http-equiv="X-UA-Compatible" content="IE=8" >
</pre>瀏覽器內(nèi)核控制:國內(nèi)瀏覽器很多都是雙內(nèi)核(webkit和Trident),webkit內(nèi)核高速瀏覽怠蹂,IE內(nèi)核兼容網(wǎng)頁和舊版網(wǎng)站善延。而添加meta標(biāo)簽的網(wǎng)站可以控制瀏覽器選擇何種內(nèi)核渲染。參考文檔
<pre><meta name="renderer" content="webkit|ie-comp|ie-stand"></pre>
國內(nèi)雙核瀏覽器默認(rèn)內(nèi)核模式如下:
搜狗高速瀏覽器城侧、QQ瀏覽器:IE內(nèi)核(兼容模式)
360極速瀏覽器易遣、遨游瀏覽器:Webkit內(nèi)核(極速模式)
禁止瀏覽器從本地計(jì)算機(jī)的緩存中訪問頁面內(nèi)容:這樣設(shè)定,訪問者將無法脫機(jī)瀏覽嫌佑。
<pre><meta http-equiv="Pragma" content="no-cache"></pre>Windows 8
<pre>
<meta name="msapplication-TileColor" content="#000"/>
<meta name="msapplication-TileImage" content="icon.png"/>
</pre>站點(diǎn)適配:主要用于PC-手機(jī)頁的對(duì)應(yīng)關(guān)系豆茫。
<pre>
<meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url">
</pre>
-
轉(zhuǎn)碼申明:用百度打開網(wǎng)頁可能會(huì)對(duì)其進(jìn)行轉(zhuǎn)碼(比如貼廣告)侨歉,避免轉(zhuǎn)碼可添加如下meta。
<pre><meta http-equiv="Cache-Control" content="no-siteapp" /></pre>