< meta > 元素
概要
標(biāo)簽提供關(guān)于HTML文檔的元數(shù)據(jù)。元數(shù)據(jù)不會(huì)顯示在頁(yè)面上,但是對(duì)于機(jī)器是可讀的。它可用于瀏覽器(如何顯示內(nèi)容或重新加載頁(yè)面),搜索引擎(關(guān)鍵詞),或其他 web 服務(wù)。
必要屬性
| 屬性 | 值 | 描述 |
|---|---|---|
| content | some text | 定義與http-equiv或name屬性相關(guān)的元信息 |
可選屬性
| 屬性 | 值 | 描述 |
|---|---|---|
| http-equiv | content-type / expire / refresh / set-cookie | 把content屬性關(guān)聯(lián)到HTTP頭部。 |
| name | author / description / keywords / generator / revised / others | 把 content 屬性關(guān)聯(lián)到一個(gè)名稱(chēng)。 |
| content | some text | 定義用于翻譯 content 屬性值的格式。 |
SEO優(yōu)化
-
頁(yè)面關(guān)鍵詞,每個(gè)網(wǎng)頁(yè)應(yīng)具有描述該網(wǎng)頁(yè)內(nèi)容的一組唯一的關(guān)鍵字。
使用人們可能會(huì)搜索,并準(zhǔn)確描述網(wǎng)頁(yè)上所提供信息的描述性和代表性關(guān)鍵字及短語(yǔ)。標(biāo)記內(nèi)容太短,則搜索引擎可能不會(huì)認(rèn)為這些內(nèi)容相關(guān)。另外標(biāo)記不應(yīng)超過(guò) 874 個(gè)字符。
<meta name="keywords" content="your tags" />
- 頁(yè)面描述,每個(gè)網(wǎng)頁(yè)都應(yīng)有一個(gè)不超過(guò) 150 個(gè)字符且能準(zhǔn)確反映網(wǎng)頁(yè)內(nèi)容的描述標(biāo)簽。
<meta name="description" content="150 words" />
- 搜索引擎索引方式,robotterms是一組使用逗號(hào)(,)分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。確保正確使用nofollow和noindex屬性值。
<meta name="robots" content="index,follow" />
<!--
all:文件將被檢索,且頁(yè)面上的鏈接可以被查詢(xún);
none:文件將不被檢索,且頁(yè)面上的鏈接不可以被查詢(xún);
index:文件將被檢索;
follow:頁(yè)面上的鏈接可以被查詢(xún);
noindex:文件將不被檢索,但頁(yè)面上的鏈接可以被查詢(xún);
nofollow:文件將不被檢索,頁(yè)面上的鏈接可以被查詢(xún)。
-->
- 頁(yè)面重定向和刷新:content內(nèi)的數(shù)字代表時(shí)間(秒),既多少時(shí)間后刷新。如果加url,則會(huì)重定向到指定網(wǎng)頁(yè)(搜索引擎能夠自動(dòng)檢測(cè),也很容易被引擎視作誤導(dǎo)而受到懲罰)。
<meta http-equiv="refresh" content="0;url=" />
- 其他
<meta name="author" content="author name" /> <!-- 定義網(wǎng)頁(yè)作者 --> <meta name="google" content="index,follow" /> <meta name="googlebot" content="index,follow" /> <meta name="verify" content="index,follow" />
移動(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。
<meta name="viewport" content="width=device-width; initial-scale=1.0;maximum-scale=1.0; user-scalable=no;"/> <!-- `width=device-width` 會(huì)導(dǎo)致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開(kāi)頁(yè)面時(shí)出現(xiàn)黑邊 -->
- width:寬度(數(shù)值 / device-width)(范圍從200 到10,000,默認(rèn)為980 像素)
- height:高度(數(shù)值 / device-height)(范圍從223 到10,000)
- initial-scale:初始的縮放比例 (范圍從>0 到10)
- minimum-scale:允許用戶(hù)縮放到的最小比例
- maximum-scale:允許用戶(hù)縮放到的最大比例
- user-scalable:用戶(hù)是否可以手動(dòng)縮 (no,yes)
- minimal-ui:可以在頁(yè)面加載時(shí)最小化上下?tīng)顟B(tài)欄。(已棄用)
注意,很多人使用initial-scale=1到非響應(yīng)式網(wǎng)站上,這會(huì)讓網(wǎng)站以100%寬度渲染,用戶(hù)需要手動(dòng)移動(dòng)頁(yè)面或者縮放。如果和initial-scale=1同時(shí)使用user-scalable=no或maximum-scale=1,則用戶(hù)將不能放大/縮小網(wǎng)頁(yè)來(lái)看到全部的內(nèi)容。
- WebApp全屏模式:偽裝app,離線(xiàn)應(yīng)用。
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 啟用 WebApp 全屏模式 -->
- 隱藏狀態(tài)欄/設(shè)置狀態(tài)欄顏色:只有在開(kāi)啟WebApp全屏模式時(shí)才生效。content的值為default | black | black-translucent 。
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
- 添加到主屏后的標(biāo)題
<meta name="apple-mobile-web-app-title" content="標(biāo)題">
- 忽略數(shù)字自動(dòng)識(shí)別為電話(huà)號(hào)碼
<meta content="telephone=no" name="format-detection" />
- 忽略識(shí)別郵箱
<meta content="email=no" name="format-detection" />
- 添加智能 App 廣告條 Smart App Banner:告訴瀏覽器這個(gè)網(wǎng)站對(duì)應(yīng)的app,并在頁(yè)面上顯示下載banner(如下圖)。參考文檔
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
- 其他 參考文檔
<!-- 針對(duì)手持設(shè)備優(yōu)化,主要是針對(duì)一些老的不識(shí)別viewport的瀏覽器,比如黑莓 --> <meta name="HandheldFriendly" content="true"> <!-- 微軟的老式瀏覽器 --> <meta name="MobileOptimized" content="320"> <!-- uc強(qiáng)制豎屏 --> <meta name="screen-orientation" content="portrait"> <!-- QQ強(qiáng)制豎屏 --> <meta name="x5-orientation" content="portrait"> <!-- UC強(qiáng)制全屏 --> <meta name="full-screen" content="yes"> <!-- QQ強(qiáng)制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- UC應(yīng)用模式 --> <meta name="browsermode" content="application"> <!-- QQ應(yīng)用模式 --> <meta name="x5-page-mode" content="app"> <!-- windows phone 點(diǎn)擊無(wú)高光 --> <meta name="msapplication-tap-highlight" content="no">
網(wǎng)頁(yè)相關(guān)
- 申明編碼
<meta charset='utf-8' />
- 優(yōu)先使用 IE 最新版本和 Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 關(guān)于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 -->
- 瀏覽器內(nèi)核控制:國(guó)內(nèi)瀏覽器很多都是雙內(nèi)核(webkit和Trident),webkit內(nèi)核高速瀏覽,IE內(nèi)核兼容網(wǎng)頁(yè)和舊版網(wǎng)站。而添加meta標(biāo)簽的網(wǎng)站可以控制瀏覽器選擇何種內(nèi)核渲染。參考文檔
<meta name="renderer" content="webkit|ie-comp|ie-stand">
國(guó)內(nèi)雙核瀏覽器默認(rèn)內(nèi)核模式如下:
1. 搜狗高速瀏覽器、QQ瀏覽器:IE內(nèi)核(兼容模式)
2. 360極速瀏覽器、遨游瀏覽器:Webkit內(nèi)核(極速模式)
- 禁止瀏覽器從本地計(jì)算機(jī)的緩存中訪問(wèn)頁(yè)面內(nèi)容:這樣設(shè)定,訪問(wèn)者將無(wú)法脫機(jī)瀏覽。
<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 磁貼圖標(biāo) -->
- 站點(diǎn)適配:主要用于PC-手機(jī)頁(yè)的對(duì)應(yīng)關(guān)系。
<meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url"> <!-- [wml|xhtml|html5]根據(jù)手機(jī)頁(yè)的協(xié)議語(yǔ)言,選擇其中一種; url="url" 后者代表當(dāng)前PC頁(yè)所對(duì)應(yīng)的手機(jī)頁(yè)URL,兩者必須是一一對(duì)應(yīng)關(guān)系。 -->
- 轉(zhuǎn)碼申明:用百度打開(kāi)網(wǎng)頁(yè)可能會(huì)對(duì)其進(jìn)行轉(zhuǎn)碼(比如貼廣告),避免轉(zhuǎn)碼可添加如下meta
<meta http-equiv="Cache-Control" content="no-siteapp" />
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。
