使用 MIME 类型 text/html 提供的页面与使用 MIME 类型 application/xhtml+xml 提供的页面的
据我所知,如果浏览器中禁用了 JavaScript,则根本不会处理 text/html 页面的
有人可以向我指出适当的 W3C 标准或提供任何其他说明吗?
PS。感兴趣的情况是访问计数服务,它使用最佳答案
最好的描述可能是 HTML5 草案中的描述:http://dev.w3.org/html5/spec/semantics.html#the-noscript-element .
在text/html中,具体发生的事情的细节是相当复杂的。只需点击上面的链接即可。没有必要在这里复制。
对于application/xhtml+xml,草案说:
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.
所以在application/xhtml+xml中,无论脚本是否可用,都应该显示noscript的内容。当然,如果启用了脚本,那么使用脚本从 DOM 中删除此类元素就非常简单了。
更正。
经过进一步研究,我认为上述引用的意思是,noscript 元素对解析没有影响。
在此处的 XHTML 部分中,http://dev.w3.org/html5/spec/the-xhtml-syntax.html#the-xhtml-syntax ,草案称
The user agent is expected to hide noscript elements for whom scripting is enabled, irrespective of CSS rules.
所以,正如您所说,当启用脚本时,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 仍然尝试加载图像。
关于xml - XML 文档中的 <noscript> 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2167453/