更新时间:2023-12-05 21:18:58
仅当<noscript>
位于body
中而不是head
中时,该方法才有效.它的行为是绝对正确的.只需考虑在<head>
中设置任何内容:该内容将不会显示.
It only works, if the <noscript>
is in the body
, not the head
. And it's absolutely correct that it behaves like that. Just think of setting any content inside the <head>
: it won't get displayed.
不起作用:<head>
<!doctype html>
<html>
<head>
<noscript>aaa</noscript>
<script>document.write("bbb")</script>
</head>
<body>
ccc
</body>
</html>
在Windows 10上使用最新的Chrome和 uBlock Origin 扩展程序进行了测试.此 codepen
Tested with latest Chrome and uBlock Origin extension on Windows 10 Pro on this codepen
将工作:<body>
中的<noscript>
<!doctype html>
<html>
<head>
</head>
<body>
<noscript>aaa</noscript>
<script>document.write("bbb")</script>
ccc
</body>
</html>
在Windows 10上使用最新的Chrome和 uBlock Origin 扩展程序进行了测试.此 codepen
Tested with latest Chrome and uBlock Origin extension on Windows 10 Pro on this codepen
在 MDN< noscript>页面(强调我的意思)
允许的内容:禁用脚本并且是< head>的后代元素:以任意顺序,零个或多个< link> 元素,零个或多个< style> 元素以及零个或多个< ; meta> 元素. 当脚本被禁用并且不是< head>的后代时,元素:任何透明的内容,但没有< noscript>元素必须在其子孙中. 否则:流内容或短语内容.
Permitted content: When scripting is disabled and when it is a descendant of the <head> element: in any order, zero or more <link> elements, zero or more <style> elements, and zero or more <meta> elements. When scripting is disabled and when it isn't a descendant of the <head> element: any transparent content, but no <noscript> element must be among its descendants. Otherwise: flow content or phrasing content.
所以:如果在头,则仅允许链接,元数据和样式
So: If in head, only link, meta and style allowed