HTML的頭部內容特別多,有針對SEO的頭部信息,也有針對移動設備的頭部信息。而且各個瀏覽器內核以及各個國內瀏覽器廠商都有些自己的標簽元素,有很多差異性。移動端的工作已經越來越成為前端工作的重要內容,除了平常的項目開發,HTML 頭部標簽功能,特別是meta,link等標簽的功能屬性顯得非常重要。這里整理了一份 <head> 部分的清單,讓大家了解每個標簽及相應屬性的意義,寫出滿足自己需求的 <head> 頭部標簽,可以很有效的增強頁面的可用性。
HTML基本的頭部標簽
下面是HTML基本的頭部元素:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!--移動端的頁面這個可以忽略,具體可以查看本文Internet Explorer瀏覽器部分-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--具體可以查看本文 為移動設備添加 viewport 部分-->
<!-- 以上 3 個 meta 標簽 *必須* 放在 head 的最前面;其他任何的 head 內容必須在這些標簽的 *后面* -->
<title>頁面標題</title>
...
</head>
其中
<meta http-equiv="x-ua-compatible" content="ie=edge">
在桌面開發的時候可以讓IE瀏覽器以最新的模式渲染頁面,具體可以查看本文Internet Explorer瀏覽器部分。如果你的頁面確定只在桌面瀏覽器中運行,那么
<meta name="viewport" content="width=device-width, initial-scale=1">
也可以省略。
DOCTYPE
DOCTYPE(Document Type),該聲明位于文檔中最前面的位置,處于 html 標簽之前,此標簽告知瀏覽器文檔使用哪種 HTML 或者 XHTML 規范。
使用 HTML5 doctype,不區分大小寫。
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區分大小寫 -->
charset
聲明文檔使用的字符編碼,
<meta charset="utf-8">
html5 之前網頁中會這樣寫:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
這兩個是等效的,具體可移步閱讀:<meta charset='utf-8'>
vs <meta http-equiv='Content-Type'>
,所以建議使用較短的,易于記憶。
lang屬性
更加標準的 lang 屬性寫法 http://zhi.hu/XyIa
簡體中文
<html lang="zh-cmn-Hans"> <!-- 更加標準的 lang 屬性寫法 http://zhi.hu/XyIa -->
繁體中文
<html lang="zh-cmn-Hant"> <!-- 更加標準的 lang 屬性寫法 http://zhi.hu/XyIa -->
很少情況才需要加地區代碼,通常是為了強調不同地區漢語使用差異,例如:
<p lang="zh-cmn-Hans">
<strong lang="zh-cmn-Hans-CN">菠蘿</strong>和<strong lang="zh-cmn-Hant-TW">鳳梨</strong>其實是同一種水果。只是大陸和臺灣稱謂不同,且新加坡、馬來西亞一帶的稱謂也是不同的,稱之為<strong lang="zh-cmn-Hans-SG">黃梨</strong>。
</p>
為什么 lang="zh-cmn-Hans" 而不是我們通常寫的 lang="zh-CN" 呢,請移步閱讀: 頁頭部的聲明應該是用 lang=”zh” 還是 lang=”zh-cn”。
Meta 標簽
meta標簽是HTML中head頭部的一個輔助性標簽,它位于HTML文檔頭部的 <head> 和 <title> 標記之間,它提供用戶不可見的信息。雖然這部分信息用戶不可見,但是其作用非常強大,特別是當今的前端開發工作中,設置合適的meta標簽可以大大提升網站頁面的可用性。
桌面端開發中,meta標簽通常用來為搜索引擎優化(SEO)及 robots定義頁面主題,或者是定義用戶瀏覽器上的cookie;它可以用于鑒別作者,設定頁面格式,標注內容提要和關鍵字;還可以設置頁面使其可以根據你定義的時間間隔刷新自己,以及設置RASC內容等級,等等。
移動端開發中,meta標簽除了桌面端中的功能設置外,還包括,比如viewport設置,添加到主屏幕圖標,標簽頁顏色等等實用設置。具體可以看后面詳細的介紹。
meta標簽分類
meta標簽根據屬性的不同,可分為兩大部分:http-equiv 和 name 屬性。
http-equiv:相當于http的文件頭作用,它可以向瀏覽器傳回一些有用的信息,以幫助瀏覽器正確地顯示網頁內容。
name屬性:主要用于描述網頁,與之對應的屬性值為content,content中的內容主要是便于瀏覽器,搜索引擎等機器人識別,等等。
推薦使用的meta標簽
<!-- 設置文檔的字符編碼 -->
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- 以上 3 個 meta 標簽 *必須* 放在 head 的最前面;其他任何的 head 內容必須在這些標簽的 *后面* -->
<!-- 允許控制資源的過度加載 -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<!-- 盡早地放置在文檔中 -->
<!-- 僅應用于該標簽下的內容 -->
<!-- Web 應用的名稱(僅當網站被用作為一個應用時才使用)-->
<meta name="application-name" content="應用名稱">
<!-- 針對頁面的簡短描述(限制 150 字符)-->
<!-- 在*某些*情況下,該描述是被用作搜索結果展示片段的一部分 -->
<meta name="description" content="一個頁面描述">
<!-- 控制搜索引擎的抓取和索引行為 -->
<meta name="robots" content="index,follow,noodp"><!-- 所有的搜索引擎 -->
<meta name="googlebot" content="index,follow"><!-- 僅對 Google 有效 -->
<!-- 告訴 Google 不顯示網站鏈接的搜索框 -->
<meta name="google" content="nositelinkssearchbox">
<!-- 告訴 Google 不提供此頁面的翻譯 -->
<meta name="google" content="notranslate">
<!-- 驗證 Google 搜索控制臺的所有權 -->
<meta name="google-site-verification" content="verification_token">
<!-- 用來命名軟件或用于構建網頁(如 - WordPress、Dreamweaver)-->
<meta name="generator" content="program">
<!-- 關于你的網站主題的簡短描述 -->
<meta name="subject" content="你的網站主題">
<!-- 非常簡短(少于 10 個字)的描述。主要用于學術論文。-->
<meta name="abstract" content="">
<!-- 完整的域名或網址 -->
<meta name="url" content="https://example.com/">
<meta name="directory" content="submission">
<!-- 基于網站內容給出一般的年齡分級 -->
<meta name="rating" content="General">
<!-- 允許控制 referrer 信息如何傳遞 -->
<meta name="referrer" content="never">
<!-- 禁用自動檢測和格式化可能的電話號碼 -->
<meta name="format-detection" content="telephone=no">
<!-- 通過設置為 “off” 完全退出 DNS 預取 -->
<meta http-equiv="x-dns-prefetch-control" content="off">
<!-- 在客戶端存儲 cookie,web 瀏覽器的客戶端識別 -->
<meta http-equiv="set-cookie" content="name=value; expires=date; path=url">
<!-- 指定要顯示在一個特定框架中的頁面 -->
<meta http-equiv="Window-Target" content="_value">
<!-- 地理標簽 -->
<meta name="ICBM" content="latitude, longitude">
<meta name="geo.position" content="latitude;longitude">
<!-- 國家代碼 (ISO 3166-1): 強制性, 州代碼 (ISO 3166-2): 可選; 如 content="US" / content="US-NY" -->
<meta name="geo.region" content="country[-state]">
<!-- 如 content="New York City" -->
<meta name="geo.placename" content="city/town">
相關的詳細說明請查看:
Google 可以識別的 Meta 標簽
WHATWG Wiki: Meta 拓展
ICBM – 維基百科
地理標記 – 維基百科
為移動設備添加 viewport
viewport 可以讓布局在移動瀏覽器上顯示的更好。 通常會寫
<!-- width=device-width` 會導致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時出現黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->
<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)
content 參數:
<pre>
width viewport 寬度(數值/device-width)
height viewport 高度(數值/device-height)
initial-scale 初始縮放比例
maximum-scale 最大縮放比例
minimum-scale 最小縮放比例
user-scalable 是否允許用戶縮放(yes/no)
</pre>
minimal-ui iOS 7.1 beta 2 中新增屬性(注意:iOS8 中已經刪除),可以在頁面加載時最小化上下狀態欄。這是一個布爾值,可以直接這樣寫:
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
而如果你的網站不是響應式的,請不要使用 initial-scale 或者禁用縮放。
<meta name="viewport" content="width=device-width,user-scalable=yes">
相關鏈接:非響應式設計的viewport
適配 iPhone 6 和 iPhone 6plus 則需要寫:
<meta name="viewport" content="width=375">
<meta name="viewport" content="width=414">
大部分 4.7~5 寸的安卓設備的 viewport 寬設為 360px,iPhone 6 上卻是 375px,大部分 5.5 寸安卓機器(比如說三星 Note)的 viewport 寬為 400,iPhone 6 plus 上是 414px。
SEO 優化部分
頁面標題<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">
相關鏈接:WEB1038 – 標記包含無效的值
百度禁止轉碼
通過百度手機打開網頁時,百度可能會對你的網頁進行轉碼,脫下你的衣服,往你的身上貼狗皮膏藥的廣告,為此可在 head 內添加
<meta http-equiv="Cache-Control" content="no-siteapp" />
相關鏈接:SiteApp 轉碼聲明
不推薦的 meta 屬性
下面是不推薦使用的 meta 屬性,因為它們采用率低,或已棄用:
<!-- 用于聲明文檔語言,但支持得不是很好。最好使用 <html lang=""> -->
<meta name="language" content="en">
<!-- Google 無視 & Bing 認為垃圾的指示器 -->
<meta name="keywords" content="你,關鍵字,在這里,不使用空格,而用逗號進行分隔">
<!-- 目前沒有在任何搜索引擎中使用過的聲明 -->
<meta name="revised" content="Sunday, July 18th, 2010, 5:15 pm">
<!-- 為垃圾郵件機器人收獲 email 地址提供了一種簡單的方式 -->
<meta name="reply-to" content="email@example.com">
<!-- 最好使用 <link rel="author"> 或 humans.txt 文件 -->
<meta name="author" content="name, email@example.com">
<meta name="designer" content="">
<meta name="owner" content="">
<!-- 告訴搜索機器人一段時間后重新訪問該網頁。這不支持,因為大多數搜索引擎使用隨機時間間隔來重新抓取網頁 -->
<meta name="revisit-after" content="7 days">
<!-- 在一段時間后將用戶重定向到新的 URL -->
<!-- W3C 建議不要使用該標簽。Google 建議使用服務器端的 301 重定向。-->
<meta http-equiv="refresh" content="300; url=https://example.com/">
<!-- 描述網站的主題 -->
<meta name="topic" content="">
<!-- 公司概要或網站目的 -->
<meta name="summary" content="">
<!-- 一個已廢棄的標簽,和關鍵詞 meta 標簽的作用相同 -->
<meta name="classification" content="business">
<!-- 是否是相同的 URL,年代久遠且不支持 -->
<meta name="identifier-URL" content="https://example.com/">
<!-- 和關鍵詞標簽類似的功能 -->
<meta name="category" content="">
<!-- 確保你的網站在所有國家和語言中都能顯示 -->
<meta name="coverage" content="Worldwide">
<!-- 和 coverage 標簽相同 -->
<meta name="distribution" content="Global">
<!-- 控制在互聯網上哪些用戶可以訪問 -->
<meta http-equiv="Pics-label" content="value">
<!-- 緩存控制 -->
<!-- 最好在服務器端配置緩存控制 -->
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
link 標簽
說到 link 標簽,估計大家的第一反應和我一樣,就是引入外部CSS樣式文件的,不錯,這是 link 標簽最最常用的功能。不過它還有很多別的用處,比如這是瀏覽器 favicon 圖標,touch圖標等等。
<!-- 有助于防止出現內容重復的問題 -->
<link rel="canonical" >
<!-- 之前用于包含 icon 鏈接,但已被廢棄并不再使用 -->
<link rel="shortlink" >
<!-- 鏈接到當前文檔的一個 AMP HTML 版本 -->
<link rel="amphtml" >
<!-- 表明一個 CSS 樣式表 -->
<link rel="stylesheet" >
<!-- 鏈接到一個指定 Web 應用程序“安裝”證書的 JSON 文件 -->
<link rel="manifest" href="manifest.json">
<!-- 鏈接到文檔的作者 -->
<link rel="author" href="humans.txt">
<!-- 指向一個適用于鏈接內容的版權申明 -->
<link rel="copyright" href="copyright.html">
<!-- 給出可能的你的另一種語言的文檔位置參考 -->
<link rel="alternate" hreflang="es">
<!-- 提供了關于作者或其他人的信息 -->
<link rel="me" type="text/html">
<link rel="me" href="mailto:name@example.com">
<link rel="me" href="sms:+15035550125">
<!-- 鏈接到一個文檔,包含當前文檔的一個歸檔鏈接 -->
<link rel="archives" title="May 2003">
<!-- 鏈接到層次結構中的頂級資源 -->
<link rel="index" title="DeWitt Clinton">
<!-- 給出該文檔的起點 -->
<link rel="start" title="Pattern Recognition 1">
<!-- 引導當前文檔的前述資源序列 -->
<link rel="prev" title="OpenSearch and OpenID? A sure way to get my attention.">
<!-- 給出一個自我參考 - 當文檔有多個可能的參考時非常有用 -->
<link rel="self" type="application/atom+xml" >
<!-- 分別是在一系列文件中的第一個、下一個、上一個和最后一個 -->
<link rel="first" >
<link rel="next" >
<link rel="previous" >
<link rel="last" >
<!-- 當使用第三方服務來維護 blog 時使用 -->
<link rel="EditURI" type="application/rsd+xml" title="RSD">
<!-- 當另一個 WordPress 博客鏈接到你的 WordPress 博客或文章時形成一個自動化的評論 -->
<link rel="pingback" >
<!-- 當你在自己的頁面上鏈接到一個 url 時通知它 -->
<link rel="webmention" >
<!-- 加載一個外部的 HTML 文件到當前 HTML 文件中 -->
<link rel="import" href="component.html">
<!-- 打開搜索 -->
<link rel="search" href="/open-search.xml" type="application/opensearchdescription+xml" title="Search Title">
<!-- Feeds -->
<link rel="alternate" type="application/rss+xml" title="RSS">
<link rel="alternate" type="application/atom+xml" title="Atom 0.3">
<!-- 預取,預載,預瀏覽 -->
<link rel="dns-prefetch" >
<link rel="preconnect" >
<link rel="prefetch" >
<link rel="prerender" >
<link rel="preload" href="image.png" as="image">
<!-- 更多信息:https://css-tricks.com/prefetching-preloading-prebrowsing/ -->
具體說明查看:https://css-tricks.com/prefetching-preloading-prebrowsing/
rss訂閱
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 -->
不推薦的link標簽
以下是不推薦使用的鏈接關系:
<link rel="shortcut icon" href="path/to/favicon.ico">
<!-- 沒有用的, 專有的和錯誤的, 詳見 https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/Y_2eFRh9BOs/gULYapoRBwAJ -->
<link rel="subresource" href="styles.css">
具體說明查看:https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/Y_2eFRh9BOs/gULYapoRBwAJ
favicon 圖標
IE 11, Chrome, Firefox, Safari, Opera支持<link>形式設置:
<link rel="icon" href="path/to/favicon-16.png" sizes="16x16" type="image/png">
<link rel="icon" href="path/to/favicon-32.png" sizes="32x32" type="image/png">
<link rel="icon" href="path/to/favicon-48.png" sizes="48x48" type="image/png">
<link rel="icon" href="path/to/favicon-62.png" sizes="62x62" type="image/png">
<link rel="icon" href="path/to/favicon-192.png" sizes="192x192" type="image/png">
注意:對于IE 10及以下版本不支持<link>形式設置,只通過將命名為favicon.ico的文件放置在網站根目錄中實現。
比較詳細的 favicon 介紹可參考:
所有關于網站圖標(和觸摸圖標)
favicon 對照表
瀏覽器及平臺詳細說明
QQ 瀏覽器(X5 內核)
QQ 瀏覽器(X5 內核)同樣適用于微信,QQ等第三方應用頁面開發。
<!-- 設置鎖定橫屏、豎屏顯示模式,portrait(橫屏),landscape(豎屏)-->
<meta name="x5-orientation" content="portrait|landscape">
<!-- 設置全屏顯示頁面 -->
<meta name="x5-fullscreen" content="true">
<!-- 開啟頁面以應用模式顯示(全屏顯示等) -->
<meta name="x5-page-mode" content="app">
360瀏覽器
設置 360 瀏覽器渲染模式:webkit 為極速內核,ie-comp 為 IE 兼容內核,ie-stand 為 IE 標準內核。
<meta name="renderer" content="webkit|ie-comp|ie-stand">
詳情文檔鏈接:瀏覽器內核控制Meta標簽說明文檔
360 瀏覽器就會在讀取到這個標簽后,立即切換對應的極速核。 另外為了保險起見再加入
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
這樣寫可以達到的效果是如果安裝了 Google Chrome Frame,則使用 GCF 來渲染頁面,如果沒有安裝 GCF,則使用最高版本的 IE 內核進行渲染。
UC 瀏覽器
設置屏幕方向
portrait 為橫屏,landscape 為豎屏。
<meta name="screen-orientation" content="portrait|landscape">
設置全屏
<meta name="full-screen" content="yes">
設置適應屏幕排版(縮放是否顯示滾動條)
UC 瀏覽器在標準排版效果實現的基礎上,提供適應屏幕的排版方式,當設置為 uc-fitscreen=yes,頁面進行縮放操作時,僅放大圖片和文字等元素,但不放大屏幕寬度,保持不出現水平(橫向)滾動條。
<meta name="viewport" content="uc-fitscreen=no|yes">
排版模式
UC 瀏覽器提供兩種排版模式,分別是適屏模式(fitscreen)及標準模式(standard),其中適屏模式簡化了一些頁面的處理,使得頁面內容更適合進行頁面閱讀、節省流量及響應更快,而標準模式則能按照標準規范對頁面進行排版及渲染。
<meta name="layoutmode" content="fitscreen|standard">
夜間模式
可以幫助用戶在低亮度或黑暗情況下更舒適的進行頁面瀏覽。由于基于網頁的應用愈加復雜,由瀏覽器實現的單一夜間模式不一定能夠適應所有情況(例如游戲應用),因此 UC 瀏覽器允許網頁設計者對其設計的頁面禁用瀏覽器的夜間模式,自行設計更適合用戶使用的夜間模式。
注意:頁面內的 frame/iframe 中的夜間模式的 meta 不生效。
<meta name="nightmode" content="enable|disable">
整頁圖片強制顯示
為了節省流量及加快速度,UC 為用戶提供了無圖模式,在實際使用中存在頁面中的圖片是不可缺少的,例如驗證碼,地圖等。通過強制圖片顯示的功能可以保證圖片顯示不受用戶的設置影響。
**注意:整頁圖片強制顯示僅對當前頁面生效,對頁面內的 frame/iframe 不生效,也不影響前進后退的頁面
<meta name="imagemode" content="force">
開啟應用模式
<meta name="browsermode" content="application">
應用模式是為方便 Web 應用及游戲開發者設置的綜合開關,通過meta標簽進行指示打開,當進入應用模式時,瀏覽器將自動調整以下參數:
<pre>
參數 狀態 說明
全屏 生效 可通過 meta 或 JS API 調用退出全屏
長按菜單 失效 可通過 JS API 調用重新生效
瀏覽器默認手勢 失效 可通過 JS API 調用重新生效
排版模式 標準模式 可通過 meta 或 JS API 調用設置其他排版模式
強制圖片顯示 生效 /
夜間模式 失效 可通過 meta 或 JS API 調用啟用夜間模式
</pre>
縮放字體
例如:禁用的 UC 瀏覽器的字體縮放功能
<meta name="wap-font-scale" content="no">
具體UC 瀏覽器文檔鏈接:UC 瀏覽器文檔
Apple iOS原生瀏覽器
添加智能 App 廣告條
告訴瀏覽器這個網站對應的app,并在頁面上顯示下載banner,需要注意的是Smart App Banners標簽不能用在frame框架內部,否則不起作用。
其中app-id(必須), affiliate-data (可選), app-argument (可選)
<meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">
例如Digg的寫法:
<meta name="apple-itunes-app" content="app-id=362872995, affiliate-data=bevbOqLt02I, app-argument=digg://">
忽略數字自動識別為電話號碼
<meta name="format-detection" content="telephone=no">
啟用 WebApp 全屏模式
<meta name="apple-mobile-web-app-capable" content="yes">
添加到主屏后設置狀態欄的背景顏色
<meta name="apple-mobile-web-app-status-bar-style" content="black">
只有在 “apple-mobile-web-app-capable” content=”yes” 時生效:
- 如果設置為 default 或 black ,網頁內容從狀態欄底部開始。
- 如果設置為 black-translucent ,網頁內容充滿整個屏幕,頂部會被狀態欄遮擋。
添加到主屏后的標題(iOS 6 新增)
<meta name="apple-mobile-web-app-title" content="App Title">
iOS 圖標
圖片自動處理成圓角和高光等效果。
<link rel="apple-touch-icon" href="path/to/apple-touch-icon.png">
禁止系統自動添加效果,直接顯示設計原圖。
<link rel="apple-touch-icon-precomposed" href="path/to/apple-touch-icon-precomposed.png">
iOS 8+ 不再支持 precomposed, 只有 apple-touch-icon 是必須的在大多數情況下,在head中一個180×180px的圖標就足夠了。如果您想要由設備確定的唯一圖標,請使用不同大小的圖標。
<link rel="apple-touch-icon" sizes="57x57" href="path/to/icon@57.png">
<link rel="apple-touch-icon" sizes="72x72" href="path/to/icon@72.png">
<link rel="apple-touch-icon" sizes="114x114" href="path/to/icon@114.png">
<link rel="apple-touch-icon" sizes="144x144" href="path/to/icon@144.png">
啟動畫面 ( 不贊成使用 )
iPad 的啟動畫面是不包括狀態欄區域的,iPhone 和 iPod touch 的啟動畫面是包含狀態欄區域的
<link rel="apple-touch-startup-image" href="path/to/startup.png">
具體描述設置請查看http://www.css88.com/archives/5480中相應的說明。
iOS 應用深度鏈接
<meta name="apple-itunes-app" content="app-id=APP-ID, app-argument=http/url-sample.com">
<link rel="alternate" href="ios-app://APP-ID/http/url-sample.com">
Google Android原生瀏覽器
標簽頁選項卡顏色
Android Lollipop 中的 Chrome 39 增加 theme-color meta 標簽,用來控制選項卡顏色。
http://updates.html5rocks.com/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
<meta name="theme-color" content="#db5945">
添加到主屏
<!-- 添加到主屏 -->
<meta name="mobile-web-app-capable" content="yes">
詳細鏈接: https://developer.chrome.com/multidevice/android/installtohomescreen
安卓應用深度鏈接(網頁上喚起應用)
<!-- Android app deep linking -->
<meta name="google-play-app" content="app-id=package-name">
<link rel="alternate" href="android-app://package-name/http/url-sample.com">
注:貌似沒測試成功,如果你知道如何正確設置,歡迎留言斧正。
Apple Safari 瀏覽器
Safari 10開始支持固定書簽頁的SVG favicons了,你可以這樣使用:
<!-- Pinned Site -->
<link rel="mask-icon" href="path/to/icon.svg" color="red">
擴展閱讀:https://yoast.com/dev-blog/safari-pinned-tab-icon-mask-icon/
Google Chrome瀏覽器
關閉chrome瀏覽器下翻譯插件
有些時候感覺chrome瀏覽器下翻譯插件很煩人,可以通過下面的代碼禁用它。
<meta name="google" value="notranslate" />
chrome瀏覽器插件安裝
有時候,你需要在你的頁面上點擊某個安卓,直接安卓你的chrome瀏覽器插件,而不是鏈接到Chrome webstore 的詳細地址再安裝,那么你可以使用:
<link rel="chrome-webstore-item" >
具體使用,請查看:Using Inline Installation
Google Chrome Mobile (只針對 Android)
從 Chrome 31 開始,你可以設置你的 Web 應用為“app mode”,如 Safari。
<!-- 鏈接到一個 manifest 并定義 manifest 的元數據。-->
<!-- manifest.json 中的例子也可以通過以下鏈接找到。-->
<link rel="manifest" href="manifest.json">
<!-- 定義你的網頁為 Web 應用 -->
<meta name="mobile-web-app-capable" content="yes">
<!-- 第一個是官方推薦格式。-->
<link rel="icon" sizes="192x192" href="nice-highres.png">
<link rel="icon" sizes="128x128" href="niceicon.png">
<!-- 所有帶 apple 前綴的格式已廢棄,所以不要使用它們。-->
<link rel="apple-touch-icon" sizes="128x128" href="niceicon.png">
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="niceicon.png">
Internet Explorer瀏覽器
模式設置
//IE8以下以IE7標準模式呈現網頁,而IE9則以IE9的標準模式呈現網頁:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
//如果安裝了GCF,則使用GCF來渲染頁面("chrome=1"),
//如果沒有安裝GCF,則使用最高版本的IE內核進行渲染("IE=edge")
<meta http-equiv="x-ua-compatible" content="ie=edge">
GCF(Google Chrome Frame )相關鏈接:https://www.chromium.org/developers/how-tos/chrome-frame-getting-started
X-UA-Compatible相關鏈接:https://blogs.msdn.microsoft.com/ie/2010/06/16/ies-compatibility-features-for-site-developers/
win8,win10下的一些設置
<meta http-equiv="cleartype" content="on">
<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">
<!--
Disable link highlighting on IE 10 on Windows Phone
具體說明查看:https://blogs.windows.com/buildingapps/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10/
-->
<meta name="msapplication-tap-highlight" content="no">
<!--Pinned sites具體說明查看:https://msdn.microsoft.com/en-us/library/dn255024(v=vs.85).aspx-->
<meta name="application-name" content="Contoso Pinned Site Caption">
<meta name="msapplication-tooltip" content="Example Tooltip Text">
<meta name="msapplication-starturl" content="/">
<meta name="msapplication-config" content="http://example.com/browserconfig.xml">
<meta name="msapplication-allowDomainApiCalls" content="true">
<meta name="msapplication-allowDomainMetaTags" content="true">
<meta name="msapplication-badge" content="frequency=30; polling-uri=http://example.com/id45453245/polling.xml">
<meta name="msapplication-navbutton-color" content="#FF3300">
<meta name="msapplication-notification" content="frequency=60;polling-uri=http://example.com/livetile">
<meta name="msapplication-square150x150logo" content="path/to/logo.png">
<meta name="msapplication-square310x310logo" content="path/to/largelogo.png">
<meta name="msapplication-square70x70logo" content="path/to/tinylogo.png">
<meta name="msapplication-wide310x150logo" content="path/to/widelogo.png">
<meta name="msapplication-task" content="name=Check Order Status;action-uri=./orderStatus.aspx?src=IE9;icon-uri=./favicon.ico">
<meta name="msapplication-task-separator" content="1">
//Windows 8 磁貼顏色
<meta name="msapplication-TileColor" content="#FF3300">
//Windows 8 磁貼圖標
<meta name="msapplication-TileImage" content="path/to/tileimage.jpg">
<meta name="msapplication-window" content="width=1024;height=768">
APP 鏈接
<!-- iOS -->
<meta property="al:ios:url" content="applinks://docs">
<meta property="al:ios:app_store_id" content="12345">
<meta property="al:ios:app_name" content="App Links">
<!-- Android -->
<meta property="al:android:url" content="applinks://docs">
<meta property="al:android:app_name" content="App Links">
<meta property="al:android:package" content="org.applinks">
<!-- Web Fallback -->
<meta property="al:web:url" content="http://applinks.org/documentation">
<!-- More info: http://applinks.org/documentation/ -->
具體請查看:App Links Docs
相關項目
Atom HTML Head 片段 – Atom HEAD 片段包
Sublime Text HTML Head 片段 – Sublime Text HEAD 片段包
head-it – HEAD 片段的 CLI 接口
vue-head – 在 Vue.js 中操作 HEAD 標簽的 meta 信息
參考閱讀文章:
HTML5 樣板文檔:HTML 標簽
HTML5 樣板文檔:擴展和定制
常用的 HTML 頭部標簽
<head> 對照表
HTML head 頭標簽
html5_header
amazeui css
DOCTYPE
WEB 工程師和設計師必學的 10 個 IOS 8 新鮮改變
本文由 愚人碼頭 發表,本文鏈接:http://www.css88.com/archives/6410