<无脚本>XML 文档中的处理

发布于 2024-08-20 04:32:25 字数 496 浏览 5 评论 0原文

据我所知

有人可以向我指出适当的 W3C 标准或提供任何其他说明吗?

附言。感兴趣的情况是使用

Is there any difference in <noscript> block processing for pages served with MIME-type text/html versus those served with MIME-type application/xhtml+xml?

As far as I noticed <noscript> block for text/html pages is not processed at all if JavaScript is disabled in browser. And what happens for application/xhtml+xml pages? I suspect that for such pages the block is still analysed when JavaScript is disabled. But I failed to find any clarification of this issue.

Could someone point me to appropriate W3C standard or provide any other clarification?

PS. Situation of interest is visit counting services wich use <noscript> block to track visitors with disabled JS. If elements (for example, zero-sized images) of <noscript> blocks are downloaded in any case then such services should broke :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2024-08-27 04:32:25

最好的描述可能是 HTML5 草案中的描述: http ://dev.w3.org/html5/spec/semantics.html#the-noscript-element

在 text/html 中,具体发生的事情的细节非常复杂。只需点击上面的链接即可。在这里没有必要复制。

对于application/xhtml+xml,草案说:

不得在 XML 文档中使用 noscript 元素。

noscript 元素仅在 HTML 语法中有效,在 XHTML 语法中无效。

所以在application/xhtml+xml中,无论是否有脚本,都应该显示noscript的内容。当然,如果启用了脚本,那么使用脚本从 DOM 中删除此类元素就非常简单了。

更正。

在进一步的研究中,我认为上面引用的意思是,noscript 元素对解析没有影响。

在此处的 XHTML 部分中, http:// dev.w3.org/html5/spec/the-xhtml-syntax.html#the-xhtml-syntax,草案说

无论 CSS 规则如何,用户代理都应该隐藏启用脚本的 noscript 元素。

因此,正如您所说,当启用脚本时, noscript 元素会隐藏其内容。然而,这就是它所做的一切,并且无论如何都会加载图像。另外,我尝试了这个:

<html xml:lang="en-GB" xmlns="http://www.w3.org/1999/xhtml" lang="en-GB">
  <head> 
    <title>Test</title>
  </head>
  <body>
    <p>Test 1</p>
    <noscript id="ns">
      <p>Test 2</p>
      <script type="text/javascript">
        document.getElementById("ns").parentNode.removeChild(document.getElementById("ns"));
      </script>
      <img src="test.gif" alt="test"/>
    </noscript>
  </body>
</html>

虽然noscript节点已从dom中删除,但Firefox仍然尝试加载图像。

The best description is probably the one in the HTML5 draft here : http://dev.w3.org/html5/spec/semantics.html#the-noscript-element.

In text/html, the details of exactly what happens are quite complex. Just follow the link above. No point in reproducing here.

For application/xhtml+xml, the draft says:

The noscript element must not be used in XML documents.

The noscript element is only effective in the HTML syntax, it has no effect in the XHTML syntax.

So in application/xhtml+xml, the contents of noscript should be displayed regardless of whether scripting is available or not. Of course, if scripting is enabled, it's pretty trivial to use script to remove such elements from the DOM.

CORRECTION.

On further research, what the above quote means I think, is that the noscript element has no effect on the parsing.

In the XHTML section here, http://dev.w3.org/html5/spec/the-xhtml-syntax.html#the-xhtml-syntax, the draft says

The user agent is expected to hide noscript elements for whom scripting is enabled, irrespective of CSS rules.

So, as you say, when scripting is enabled the noscript element does hide its contents. However, that's all it does, and images are loaded anyway. In addition, I tried this:

<html xml:lang="en-GB" xmlns="http://www.w3.org/1999/xhtml" lang="en-GB">
  <head> 
    <title>Test</title>
  </head>
  <body>
    <p>Test 1</p>
    <noscript id="ns">
      <p>Test 2</p>
      <script type="text/javascript">
        document.getElementById("ns").parentNode.removeChild(document.getElementById("ns"));
      </script>
      <img src="test.gif" alt="test"/>
    </noscript>
  </body>
</html>

And although the noscript node is removed from the dom, Firefox still tried to load the image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文