元數據(metadata)是關於數據的信息。 標籤提供關於 HTML 文檔的元數據。元數據不會顯示在頁面上,可是對於機器是可讀的。
典型的狀況是,meta 元素被用於規定頁面的描述、關鍵詞、文檔的做者、最後修改時間以及其餘元數據。 標籤始終位於 head 元素中。
元數據可用於瀏覽器(如何顯示內容或從新加載頁面),搜索引擎(關鍵詞),或其餘 web 服務。
其實對上面的概念簡單總結下就是:<meta> 標籤提供關於 HTML 文檔的元數據。它不會顯示在頁面上,可是對於機器是可讀的。可用於瀏覽器(如何顯示內容或從新加載頁面),搜索引擎(關鍵詞),或其餘 web 服務。html
meta裏的數據是供機器解讀的,告訴機器該如何解析這個頁面,還有一個用途是能夠添加服務器發送到瀏覽器的http頭部內容,例如咱們爲頁面中添加以下meta標籤:web
<meta http-equiv="charset" content="iso-8859-1"> <meta http-equiv="expires" content="31 Dec 2008">
那麼瀏覽器的頭部就會包括這些:chrome
charset:iso-8859-1 expires:31 Dec 2008
固然,只有瀏覽器能夠接受這些附加的頭部字段,並能以適當的方式使用它們時,這些字段纔有意義。windows
meta的必需屬性是content,固然並非說meta標籤裏必定要有content,而是當有http-equiv或name屬性的時候,必定要有content屬性對其進行說明。例如:瀏覽器
<meta name="keywords" content="HTML,ASP,PHP,SQL">
這裏面content裏的屬性就是對keywords進行的說明,因此呢也能夠理解成一個鍵值對吧,就是{keywords:"HTML,ASP,PHP,SQL"}
。服務器
在W3school中,對於meta的可選屬性說到了三個,分別是http-equiv、name和scheme。考慮到scheme不是很經常使用,因此就只說下前兩個屬性吧。app
http-equiv
屬性是添加http頭部內容,對一些自定義的,或者須要額外添加的http頭部內容,須要發送到瀏覽器中,咱們就能夠是使用這個屬性。在上面的meta做用中也有簡單的說明,那麼如今再舉個例子。例如咱們不想使用js來重定向,用http頭部內容控制,那麼就能夠這樣控制:工具
<meta http-equiv="Refresh" content="5;url=http://blog.yangchen123h.cn" />
在頁面中加入這個後,5秒鐘後就會跳轉到指定頁面啦,效果可看W3school的例子佈局
第二個可選屬性是name,這個屬性是供瀏覽器進行解析,對於一些瀏覽器兼容性問題,name屬性是最經常使用的,固然有個前提就是瀏覽器可以解析你寫進去的name屬性才能夠,否則就是沒有意義的。仍是舉個例子吧:優化
<meta name="renderer" content="webkit">
這個meta標籤的意思就是告訴瀏覽器,用webkit內核進行解析,固然前提是瀏覽器有webkit內核才能夠,否則就是沒有意義的啦。固然看到這個你可能會有疑問,這個renderer是從哪裏冒出來的,我要怎麼知道呢?這個就是在對應的瀏覽器的開發文檔裏就會有代表的,例如這個renderer是在360瀏覽器裏說明的。360瀏覽器內核控制Meta標籤說明文檔
charset是聲明文檔使用的字符編碼,解決亂碼問題主要用的就是它,值得一提的是,這個charset必定要寫第一行,否則就可能會產生亂碼了。
charset有兩種寫法
<meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
兩個都是等效的。
百度會自動對網頁進行轉碼,這個標籤是禁止百度的自動轉碼
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 頁面標題<title>標籤(head 頭部必須) --> <title>your title</title> <!-- 頁面關鍵詞 keywords --> <meta name="keywords" content="your keywords"> <!-- 頁面描述內容 description --> <meta name="description" content="your description"> <!-- 定義網頁做者 author --> <meta name="author" content="author,email address"> <!-- 定義網頁搜索引擎索引方式,robotterms 是一組使用英文逗號「,」分割的值,一般有以下幾種取值:none,noindex,nofollow,all,index和follow。 --> <meta name="robots" content="index,follow">
viewport主要是影響移動端頁面佈局的,例如:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
content 參數:
<!-- 優先使用最新的ie版本 --> <meta http-equiv="x-ua-compatible" content="ie=edge"> <!-- 是否開啓cleartype顯示效果 --> <meta http-equiv="cleartype" content="on"> <meta name="skype_toolbar" content="skype_toolbar_parser_compatible"> <!-- Pinned Site --> <!-- IE 10 / Windows 8 --> <meta name="msapplication-TileImage" content="pinned-tile-144.png"> <meta name="msapplication-TileColor" content="#009900"> <!-- IE 11 / Windows 9.1 --> <meta name="msapplication-config" content="ieconfig.xml">
<!-- 優先使用最新的chrome版本 --> <meta http-equiv="X-UA-Compatible" content="chrome=1" /> <!-- 禁止自動翻譯 --> <meta name="google" value="notranslate">
<!-- 選擇使用的瀏覽器解析內核 --> <meta name="renderer" content="webkit|ie-comp|ie-stand">
<!-- 將屏幕鎖定在特定的方向 --> <meta name="screen-orientation" content="landscape/portrait"> <!-- 全屏顯示頁面 --> <meta name="full-screen" content="yes"> <!-- 強制圖片顯示,即便是"text mode" --> <meta name="imagemode" content="force"> <!-- 應用模式,默認將全屏,禁止長按菜單,禁止手勢,標準排版,強制圖片顯示。 --> <meta name="browsermode" content="application"> <!-- 禁止夜間模式顯示 --> <meta name="nightmode" content="disable"> <!-- 使用適屏模式顯示 --> <meta name="layoutmode" content="fitscreen"> <!-- 當頁面有太多文字時禁止縮放 --> <meta name="wap-font-scale" content="no">
<!-- 鎖定屏幕在特定方向 --> <meta name="x5-orientation" content="landscape/portrait"> <!-- 全屏顯示 --> <meta name="x5-fullscreen" content="true"> <!-- 頁面將以應用模式顯示 --> <meta name="x5-page-mode" content="app">
<!-- Smart App Banner --> <meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT"> <!-- 禁止自動探測並格式化手機號碼 --> <meta name="format-detection" content="telephone=no"> <!-- Add to Home Screen添加到主屏 --> <!-- 是否啓用 WebApp 全屏模式 --> <meta name="apple-mobile-web-app-capable" content="yes"> <!-- 設置狀態欄的背景顏色,只有在 「apple-mobile-web-app-capable」 content=」yes」 時生效 --> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <!-- 添加到主屏後的標題 --> <meta name="apple-mobile-web-app-title" content="App Title">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection"content="telephone=no, email=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /><!-- 刪除蘋果默認的工具欄和菜單欄 --> <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"> <!-- 針對手持設備優化,主要是針對一些老的不識別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"> <!-- 適應移動端end -->