在HTML网页中,带有脚本阻止扩展名的浏览器不会呈现noscript标记内的内容 [英] In HTML webpage, the content within noscript tags are not getting rendered by browsers with script blocking extension

查看:150
本文介绍了在HTML网页中,带有脚本阻止扩展名的浏览器不会呈现noscript标记内的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML网页中,具有脚本阻止扩展名的浏览器不会呈现noscript标记内的内容.

In HTML webpage, the content within noscript tags are not getting rendered by browsers with script blocking extension.

我有一个页面

http://www.zen76171.zen.co.uk/aaa2.html

使用此HTML

<!doctype html>
<html>
<head>
<noscript>aaa</noscript>
<script>document.write("bbb")</script>
</head>
<body>
ccc
</body>
</html>

我了解到,如果浏览器未运行javascript,则应运行noscript标记的内容.

I understand that the contents of the noscript tag should run if a browser is not running javascript.

在chrome或firefox中,没有扩展阻止任何内容,我得到了bbb ccc的输出.很好,那是有道理的.显示"bbb"是因为允许使用javascript,而显示ccc是因为它将显示是否启用了javascript.

In chrome or firefox, with no extensions blocking anything, I get the output of bbb ccc. That's fine, that makes sense. 'bbb' shows because javascript is allowed, and ccc shows because it will show whether javascript is enabled or not.

如果我安装例如uBlock原始扩展名,或者如果在Firefox中安装了NoScript扩展名(请注意,该扩展名的名称与noscript标签一致),那么当我重新加载页面时,我会提到

If I install e.g. the uBlock origin extension or if in Firefox I install the NoScript extension(note- the name of that extension is coincidentally the same as the noscript tag), then when I reload the page I mentioned

http://www.zen76171.zen.co.uk/aaa2.html

它显示ccc.这向我表明脚本被阻止了(因为它没有显示bbb,所以该部分(不显示bbb很好).

It shows ccc. That indicates to me that scripts are being blocked (as it didn't show bbb, so that part(not showing bbb, is good.

但是我希望的输出是aaa ccc,因为我希望在禁用脚本和禁用脚本时显示'aaa'.

But the output I would expect is aaa ccc, because I'd expect 'aaa' to show when scripts are disabled, and scripts are disabled.

还有另一个我要解决的问题,即如果我禁用甚至从Firefox中删除了NoScript扩展,那么我仍然会收到与"ccc"相同的响应,我必须卸载并重新安装Firefox删除NoScript扩展.但是现在,当我想删除NoScript扩展名时,就可以这样做. uBlock Origin没有这样的问题(无需重新安装浏览器即可将其删除!).因此,如果有人尝试重现此问题,那么我建议他们要么使用自己拥有的脚本阻止程序,要么像我一样使用uBlock Origin.

There is also a secondary problem that I work around, which is that if I disable or even 'remove' the NoScript extension from Firefox, then I still get the same response of 'ccc', I have to uninstall and reinstall Firefox to remove the NoScript extension. But for now that will do when I want to remove the NoScript extension. uBlock Origin has no such issue(don't need to reinstall a browser to remove it!). So if anybody tries to reproduce this problem then I suggest they either use the script blocker they have, or as I have, use uBlock Origin.

为什么只显示'ccc'而不显示'aaa ccc'(当脚本被阻止时)?

Why does it show just 'ccc' and not 'aaa ccc' (when scripts are blocked)?

uBlock Origin或NoScript扩展就是这种情况.因此,似乎可以禁用脚本的任何东西.

This is the case with uBlock Origin, or with the NoScript extension. So, it seems, it's with anything that disables scripts.

所以,为什么aaa从未显示过.我认为应该在禁用脚本时显示它.

So, why is the aaa not being displayed ever. I'd think it should be displayed when scripts are disabled.

推荐答案

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

这篇关于在HTML网页中,带有脚本阻止扩展名的浏览器不会呈现noscript标记内的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆