欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

实例讲解HTML5的meta标签的一些应用 _html5教程技巧

程序员文章站 2022-03-09 13:21:13
...
HTML 4.01 与 HTML 5 之间meta标签用法的主要差异:

在 HTML 5 中,不再支持 scheme 属性。

在 HTML 5 中,有一个新的 charset 属性,它使字符集的定义更加容易。

在 HTML 4.01 中,不得不这么写:

XML/HTML Code复制内容到剪贴板
  1. meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

在 HTML 5 中,这样就够了:

XML/HTML Code复制内容到剪贴板
  1. meta charset="ISO-8859-1">

例子

定义针对搜索引擎的关键词:

XML/HTML Code复制内容到剪贴板
  1. meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript" />

定义对页面的描述:

XML/HTML Code复制内容到剪贴板
  1. meta name="description" content="免费的 web 技术教程。" />

定义页面的最新版本:

XML/HTML Code复制内容到剪贴板
  1. meta name="revised" content="David, 2008/8/8/" />

每 5 秒刷新一次页面:

XML/HTML Code复制内容到剪贴板
  1. meta http-equiv="refresh" content="5" />

属性
实例讲解HTML5的meta标签的一些应用 _html5教程技巧

标准属性

class, contenteditable, contextmenu, dir, draggable, id, irrelevant, lang, ref, registrationmark, tabindex, template, title如需完整的描述,请访问 HTML 5 中标准属性。

事件属性

onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu, ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup, onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout, onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload如需完整的描述,请访问 HTML 5 中事件属性。

实例

文档描述

XML/HTML Code复制内容到剪贴板
  1. html>
  2. head>
  3. meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. meta name="author" content="w3school.com.cn">
  5. meta name="revised" content="David Yang,8/1/07">
  6. meta name="generator" content="Dreamweaver 8.0en">
  7. head>
  8. body>
  9. p>本文档的 meta 属性标识了创作者和编辑软件。p>
  10. body>
  11. html>

Meta 元素中的信息可以描述 HTML 文档。

文档关键字

XML/HTML Code复制内容到剪贴板
  1. html>
  2. head>
  3. meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. meta name="description" content="HTML examples">
  5. meta name="keywords" content="HTML, DHTML, CSS, XML, XHTML, JavaScript, VBScript">
  6. head>
  7. body>
  8. p>本文档的 meta 属性描述了该文档和它的关键词。p>
  9. body>
  10. html>

Meta 元素中的信息可以描述文档的关键词。

重定向

XML/HTML Code复制内容到剪贴板
  1. html>
  2. head>
  3. meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn">
  5. head>
  6. body>
  7. p>
  8. 对不起。我们已经搬家了。您的 URL 是 a href="http://www.w3school.com.cn"> http://www.w3school.com.cn a>
  9. p>
  10. p>您将在 5 秒内被重定向到新的地址。p>
  11. p>如果超过 5 秒后您仍然看到本消息,请点击上面的的链接。p>
  12. body>
  13. html>

这个例子演示:在网址已经变更的情况下,将用户重定向到另外一个地址。

移动前端开发中添加一些webkit专属的HTML5头部标签,帮助浏览器更好解析html代码,更好地将移动web前端页面表现出来。本文整理一些常用的meta标签。

XML/HTML Code复制内容到剪贴板
  1. /span>>
  2. html lang="zh-cmn-Hans">
  3. head>
  4. meta charset='utf-8'>
  5. meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  6. meta name="description" content="不超过150个字符"/>
  7. meta name="keywords" content=""/>
  8. meta name="author" content="name, email@gmail.com"/>
  9. meta name="robots" content="index,follow"/>
  10. meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
  11. meta name="apple-mobile-web-app-title" content="标题">
  12. meta name="apple-mobile-web-app-capable" content="yes"/>
  13. meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
  14. meta name="apple-mobile-web-app-status-bar-style" content="black"/>
  15. meta name="format-detection" content="telphone=no, email=no"/>
  16. meta name="renderer" content="webkit">
  17. meta http-equiv="X-UA-Compatible" content="IE=edge">
  18. meta http-equiv="Cache-Control" content="no-siteapp" />
  19. meta name="HandheldFriendly" content="true">
  20. meta name="MobileOptimized" content="320">
  21. meta name="screen-orientation" content="portrait">
  22. meta name="x5-orientation" content="portrait">
  23. meta name="full-screen" content="yes">
  24. meta name="x5-fullscreen" content="true">
  25. meta name="browsermode" content="application">
  26. meta name="x5-page-mode" content="app">
  27. meta name="msapplication-tap-highlight" content="no">
  28. link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png"/>
  29. link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png"/>
  30. link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png"/>
  31. link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png"/>
  32. link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png"/>
  33. link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png"/>
  34. link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png"/>
  35. link rel="apple-touch-startup-image" href="/splash-screen-320x480.png"/>
  36. link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png"/>
  37. link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png"/>
  38. meta name="msapplication-TileColor" content="#000"/>
  39. meta name="msapplication-TileImage" content="icon.png"/>
  40. link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml"/>
  41. link rel="shortcut icon" type="image/ico" href="/favicon.ico"/>
  42. meta property="og:type" content="类型" />
  43. meta property="og:url" content="URL地址" />
  44. meta property="og:title" content="标题" />
  45. meta property="og:image" content="图片" />
  46. meta property="og:description" content="描述" />
  47. title>标题title>
  48. head>
相关标签: HTML5 meta