xhtml - 错误 "noscript",W3C XHTML

标签 xhtml w3c-validation head noscript

我正在尝试将我的文档验证为 XHTML 1.0 Transitional (W3C)。

我有以下错误: “文档类型不允许此处使用元素“noscript”;假设缺少“对象”开始标记” 对应于这段代码:

<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1096/?
value=1.00&amp;label=Y-skCMY_QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>
</head>

但是我的验证失败了。问题是什么?请帮我解决这个问题。

最佳答案

您的解决方案之一可能是将其放在 body 中而不是 head您的文档如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1096/?
value=1.00&amp;label=Y-skCMY_QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>
</body>
</html>

这会导致:

This document was successfully checked as XHTML 1.0 Transitional!

此外,根据this answer ,这似乎并没有真正的区别(我在这里谈论 headbody ):

Have done the move with the Google Ad section outside of HEAD and just in the BODY part itself. Really doesn't make a difference since when it was moved, it was just right after the parameters used for the ads to display.

解决方案#2 如果您需要删除 <noscript>无论如何,您可以尝试进行以下操作:

<div id='noscript' style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1096/?
value=1.00&amp;label=Y-skCMY_QM&amp;guid=ON&amp;script=0"/>
</div>
<script>document.getElementById('noscript').style.display='none'</script>

这使得事情的工作方式与第一个解决方案完全相同。如果 JavaScript 被禁用,<script>...</script>不会被执行,因此 <div>...</div>将显示。

关于xhtml - 错误 "noscript",W3C XHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28241669/

相关文章:

css - 为什么对齐 ="center"不覆盖 {text-align :right;}

xhtml - <td align ="left"valign ="top"> 为什么这不会在 W3C 验证器中产生错误?

HTML 5 w3c 验证

javascript - 如何使用 JavaScript 定位 CSS 链接

PHP CSS - 加载外部文件或回显到头部的更快/良好实践?

php - XHTML 验证 : character "" not allowed in prolog. 为什么?

jQuery.html() 返回无效的 IMG

jquery - CSS/JQuery 菜单导航

css - W3C 验证错误 : "NET-enabling start-tag not immediately followed by null end-tag" and others

javascript - 如何使用 Javascript 将 CSS、META 等标签插入到 head 标签中?