错误 "noscript",W3C XHTML

Errors "noscript", W3C XHTML

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

我有以下错误: "document type does not allow element "noscript" 在这里;假设缺少 "object" 开始标签" 对应于此代码:

<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>