meta標籤web開發中的用途說明,meta標籤web用途
meta標籤提供關於HTML文檔的中繼資料。它可用於“告訴”瀏覽器該如何顯示內容、重新載入頁面,搜尋引擎指定關鍵詞,或用於其他 web 服務。
meta標籤屬性
| 屬性 |
值 |
描述 |
| 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 charset='utf-8' />
<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">
<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼顏色 --><meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁貼表徵圖 -->
<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" />