【问题标题】:W3C validator : Element head is missing a required instance of child element titleW3C 验证器:元素头缺少子元素标题的必需实例
【发布时间】:2014-06-16 18:23:14
【问题描述】:

您好,我正在通过 w3c 验证器验证我的 HTML 代码。但它显示错误元素头缺少子元素标题的必需实例。

网址是 http://nitansh.fwd.wf/article/travel/best-all-inclusive-resorts-for-romance/3189783/

当标题出现在 html 正文的头部时

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>      Best all-inclusive resorts for romance- NowU
</title>
<link rel="stylesheet" href="/static/css/styles.css">
<link rel="stylesheet" href="/static/css/video-js.css">
<link rel="stylesheet" href="/static/css/font-awesome.min.css">
<link rel="stylesheet" media="print" href="/static/css/print.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
 <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js">
 </script>
 <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js">
 </script>
 <![endif]-->
 <link rel="stylesheet" href="/static/css/socialsharing.css">
 <link rel="canonical" href="/article/travel/best-all-inclusive-resorts-for-romance/3189783/">




  <meta name="description" content="Whether for a honeymoon, anniversary, or private escape, these resorts fit the romantic bill.">
  <meta property="og:description" content="Whether for a honeymoon, anniversary, or private escape, these resorts fit the romantic bill.">


  <meta name="twitter:card" value="Whether for a honeymoon, anniversary, or private escape, these resorts fit the romantic bill.">



  <meta property="og:title" content="Best all-inclusive resorts for romance">


  <meta property="og:type" content="article">


  <meta property="og:url" content="http://nitansh.fwd.wf/article/travel/best-all-inclusive-resorts-for-romance/3189783/">


  <meta property="og:image" content="http://www.gannett-cdn.com/media/USATODAY/USATODAY/2013/06/18/1371593281000-Earlyne-s-luggage-1306181810_3_4.jpg"></head>

【问题讨论】:

  • "当标题出现在头部" 你确定吗?
  • 是的,您可以通过检查元素来检查。
  • 发布你的代码的 head 部分
  • 文档的head 中肯定有一个title 元素。
  • @David Thomas:不——显然正在发生重定向。我猜 OP 正在尝试验证重定向的来源,其中 title 元素肯定是缺失的。

标签: javascript html title w3c-validation


【解决方案1】:

仅供参考,这是验证器在您的代码中看到的内容

<head>
<script src="//cdn.optimizely.com/js/687271175.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="UTF-8">
</head>

您可以通过打开验证器中的显示源选项来查看这一点。也许是时候研究渐进增强了?

【讨论】:

  • 是的,但为什么会发生这种情况,就像我能够在我的浏览器中访问整个页面一样。但是 facebook 爬虫和 W3c 爬虫都显示没有像检查元素那样打开整个页面
  • @nitanshbareja 如果您关闭带有尾随 / 的元标记,您会从验证中获得更好的结果吗? &lt;meta charset="UTF-8" /&gt;
  • 当我禁用 javascript 时页面没有呈现,所以 W3C 验证器现在选择了其他东西,正在调试当页面上禁用 javascript 时它呈现什么? :)
【解决方案2】:

与您的other question 中的解决方案相同:

您正在使用 JavaScript 注入 title 元素,但 W3C 验证器不执行 JavaScript。

【讨论】:

  • 我没有用 JavaScript 注入它,原因仍然是使用 django 进行调试并在我的本地运行它并使用 forward 实用程序转发端口:)
  • @nitanshbareja:现在你的页面是 404,但是当它仍然可以在线访问时,title 元素只是用 JavaScript 添加的。如果没有 JS,你的 head 只有 1 个 meta 和 2 个 script 元素。
  • 是的,我关闭了 Tunel,但是您如何调试它?
  • @nitanshbareja:不再是了。我在它还在网上的时候就做了。在浏览器中禁用 JavaScript 并查看源代码:这也是验证器将看到的内容。
猜你喜欢
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多