HTML meta標籤總結

移動前端開發中添加一些webkit專屬的HTML5頭部標籤,幫助瀏覽器更好解析HTML代碼,更好地將移動web前端頁面表現出來。本文整理一些常用的meta標籤

<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區分大小寫 -->
<html lang="zh-cmn-Hans"> <!-- 更加標準的 lang 屬性寫法 http://zhi.hu/XyIa -->
<head>
    <!-- 聲明文檔使用的字符編碼 -->
    <meta charset='utf-8'>
    <!-- 優先使用 IE 最新版本和 Chrome -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!-- 頁面描述 -->
    <meta name="description" content="不超過150個字符"/>
    <!-- 頁面關鍵詞 -->
    <meta name="keywords" content=""/>
    <!-- 網頁作者 -->
    <meta name="author" content="name, [email protected]"/>
    <!-- 搜索引擎抓取 -->
    <meta name="robots" content="index,follow"/>
    <!-- 爲移動設備添加 viewport -->
    <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
    <!-- `width=device-width` 會導致 iPhone 5 添加到主屏後以 WebApp 全屏模式打開頁面時出現黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->

    <!-- iOS 設備 begin -->
    <meta name="apple-mobile-web-app-title" content="標題">
    <!-- 添加到主屏後的標題(iOS 6 新增) -->
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <!-- 是否啓用 WebApp 全屏模式,刪除蘋果默認的工具欄和菜單欄 -->

    <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
    <!-- 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) -->
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <!-- 設置蘋果工具欄顏色 -->
    <meta name="format-detection" content="telphone=no, email=no"/>
    <!-- 忽略頁面中的數字識別爲電話,忽略email識別 -->
    <!-- 啓用360瀏覽器的極速模式(webkit) -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 不讓百度轉碼 -->
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!-- 針對手持設備優化,主要是針對一些老的不識別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">
    <!-- iOS 圖標 begin -->
    <link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png"/>
    <!-- iPhone 和 iTouch,默認 57x57 像素,必須有 -->
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png"/>
    <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png"/>
    <!-- Retina iPad,144x144 像素,可以沒有,但推薦有 -->
    <!-- iOS 圖標 end -->

    <!-- iOS 啓動畫面 begin -->
    <link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png"/>
    <!-- iPad 豎屏 768 x 1004(標準分辨率) -->
    <link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png"/>
    <!-- iPad 豎屏 1536x2008(Retina) -->
    <link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png"/>
    <!-- iPad 橫屏 1024x748(標準分辨率) -->
    <link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png"/>
    <!-- iPad 橫屏 2048x1496(Retina) -->

    <link rel="apple-touch-startup-image" href="/splash-screen-320x480.png"/>
    <!-- iPhone/iPod Touch 豎屏 320x480 (標準分辨率) -->
    <link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png"/>
    <!-- iPhone/iPod Touch 豎屏 640x960 (Retina) -->
    <link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png"/>
    <!-- iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) -->
    <!-- iOS 啓動畫面 end -->

    <!-- iOS 設備 end -->
    <meta name="msapplication-TileColor" content="#000"/>
    <!-- Windows 8 磁貼顏色 -->
    <meta name="msapplication-TileImage" content="icon.png"/>
    <!-- Windows 8 磁貼圖標 -->

    <link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml"/>
    <!-- 添加 RSS 訂閱 -->
    <link rel="shortcut icon" type="image/ico" href="/favicon.ico"/>
    <!-- 添加 favicon icon -->

    <!-- sns 社交標籤 begin -->
    <!-- 參考微博API -->
    <meta property="og:type" content="類型" />
    <meta property="og:url" content="URL地址" />
    <meta property="og:title" content="標題" />
    <meta property="og:image" content="圖片" />
    <meta property="og:description" content="描述" />
    <!-- sns 社交標籤 end -->

    <title>標題</title>
</head>

上面給出了常用的一些meta屬性,下面給一個對meta使用的理解。

meta是html語言head區的一個輔助性標籤。也許你認爲這些代碼可有可無。其實如果你能夠用好meta標籤,會給你帶來意想不到的效果,meta標籤的作用有:搜索引擎優化(seo),定義頁面使用語言,自動刷新並指向新的頁面,實現網頁轉換時的動態效果,控制頁面緩衝,網頁定級評價,控制網頁顯示的窗口等!

html的meta總結


meta標籤的組成:meta標籤共有兩個屬性,它們分別是http-equiv屬性和name屬性,不同的屬性又有不同的參數值,這些不同的參數值就實現了不同的網頁功能。

1、name屬性


name屬性主要用於描述網頁,與之對應的屬性值爲content,content中的內容主要是便於搜索引擎機器人查找信息和分類信息用的。

meta標籤的name屬性語法格式是:

<meta name="參數"content="具體的參數值">

其中name屬性主要有以下幾種參數: 

A、Keywords(關鍵字)

說明:keywords用來告訴搜索引擎你網頁的關鍵字是什麼。

舉例:

<meta name="keywords"content="meta總結,html meta,meta屬性,meta跳轉"> 
B、description(網站內容描述)

說明:description用來告訴搜索引擎你的網站主要內容。

舉例:

<meta name="description"content="haorooms博客,html的meta總結,meta是html語言head區的一個輔助性標籤。"> 
C、robots(機器人嚮導)

說明:robots用來告訴搜索機器人哪些頁面需要索引,哪些頁面不需要索引。

content的參數有all,none,index,noindex,follow,nofollow。默認是all。

舉例:

<meta name="robots"content="none"> 

具體參數如下:

信息參數爲all:文件將被檢索,且頁面上的鏈接可以被查詢;

信息參數爲none:文件將不被檢索,且頁面上的鏈接不可以被查詢;

信息參數爲index:文件將被檢索;

信息參數爲follow:頁面上的鏈接可以被查詢;

信息參數爲noindex:文件將不被檢索,但頁面上的鏈接可以被查詢;

信息參數爲nofollow:文件將被檢索,但頁面上的鏈接不可以被查詢;

D、author(作者)

說明:標註網頁的作者

舉例:

<meta name="author"content="root,[email protected]"> 
E、generator
<meta name="generator"content="信息參數"/> 

meta標籤的generator的信息參數,代表說明網站的採用的什麼軟件製作。

F、COPYRIGHT
<META NAME="COPYRIGHT"CONTENT="信息參數"> 

meta標籤的COPYRIGHT的信息參數,代表說明網站版權信息。

G、revisit-after
<META name="revisit-after"CONTENT="7days"> 

revisit-after代表網站重訪,7days代表7天,依此類推。

2、http-equiv屬性


http-equiv顧名思義,相當於http的文件頭作用,它可以向瀏覽器傳回一些有用的信息,以幫助正確和精確地顯示網頁內容,與之對應的屬性值爲content,content中的內容其實就是各個參數的變量值。

meta標籤的http-equiv屬性語法格式是:

<meta http-equiv="參數"content="參數變量值">
其中http-equiv屬性主要有以下幾種參數:

A、Expires(期限)

說明:可以用於設定網頁的到期時間。一旦網頁過期,必須到服務器上重新傳輸。

用法:

<meta http-equiv="expires"content="Fri,12Jan200118:18:18GMT">

注意:必須使用GMT的時間格式。

B、Pragma(cache模式)

說明:禁止瀏覽器從本地計算機的緩存中訪問頁面內容。

用法:

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

注意:這樣設定,訪問者將無法脫機瀏覽。

C、Refresh(刷新)

說明:自動刷新並指向新頁面。

用法:

<meta http-equiv="Refresh"content="2;URL=http://www.haorooms.com"> //(注意後面的引號,分別在秒數的前面和網址的後面) 

注意:其中的2是指停留2秒鐘後自動刷新到URL網址。

D、Set-Cookie(cookie設定)

說明:如果網頁過期,那麼存盤的cookie將被刪除。

用法:

<meta http-equiv="Set-Cookie"content="cookie value=xxx;expires=Friday,12-Jan-200118:18:18GMT;path=/"> 

注意:必須使用GMT的時間格式。

E、Window-target(顯示窗口的設定)

說明:強制頁面在當前窗口以獨立頁面顯示。

用法:

<meta http-equiv="Window-target"content="_top"> 

注意:用來防止別人在框架裏調用自己的頁面。

F、content-Type(顯示字符集的設定)

說明:設定頁面使用的字符集。

用法:

<meta http-equiv="content-Type"content="text/html;charset=gb2312"> 

具體如下:

meta標籤的charset的信息參數如GB2312時,代表說明網站是採用的編碼是簡體中文;

meta標籤的charset的信息參數如BIG5時,代表說明網站是採用的編碼是繁體中文;

meta標籤的charset的信息參數如iso-2022-jp時,代表說明網站是採用的編碼是日文;

meta標籤的charset的信息參數如ks_c_5601時,代表說明網站是採用的編碼是韓文;

meta標籤的charset的信息參數如ISO-8859-1時,代表說明網站是採用的編碼是英文;

meta標籤的charset的信息參數如UTF-8時,代表世界通用的語言編碼;

G、content-Language(顯示語言的設定)

用法:

<meta http-equiv="Content-Language"content="zh-cn"/>
H、Cache-Control指定請求和響應遵循的緩存機制。

Cache-Control指定請求和響應遵循的緩存機制。在請求消息或響應消息中設置Cache-Control並不會修改另一個消息處理過程中的緩存處理過程。請求時的緩存指令包括no-cache、no-store、max-age、max-stale、min-fresh、on

ly-if-cached,響應消息中的指令包括public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age。各個消息中的指令含義如下

Public指示響應可被任何緩存區緩存

Private指示對於單個用戶的整個或部分響應消息,不能被共享緩存處理。這允許服務器僅僅描述當用戶的部分響應消息,此響應消息對於其他用戶的請求無效

no-cache指示請求或響應消息不能緩存

no-store用於防止重要的信息被無意的發佈。在請求消息中發送將使得請求和響應消息都不使用緩存。

max-age指示客戶機可以接收生存期不大於指定時間(以秒爲單位)的響應

min-fresh指示客戶機可以接收響應時間小於當前時間加上指定時間的響應

max-stale指示客戶機可以接收超出超時期間的響應消息。如果指定max-stale消息的值,那麼客戶機可以接收超出超時期指定值之內的響應消息。

J、http-equiv=”imagetoolbar”
<meta http-equiv="imagetoolbar"content="false"/> 

指定是否顯示圖片工具欄,當爲false代表不顯示,當爲true代表顯示。

K、Content-Script-Type
<Meta http-equiv="Content-Script-Type"Content="text/javascript">

HTML < base > 標籤


爲頁面上所有鏈接指定默認打開方式:

例如:

<base target="_self">

指定頁面中所有標籤都是本頁打開!

參考:http://www.haorooms.com/post/html_meta_ds

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章