使用 Google Chrome 最新稳定版本打开此页面(HTTPS,由于其他依赖项,必须使用 HTTPS)https://example.com/test.php
在页面内,我只有此代码(这是 Brother 打印机维护页):
<iframe sandbox="" id="iframe_display_modules" src="https://192.168.1.57/general/information.html?kind=item"></iframe>
现在,Google Chrome 不尊重我使用“沙箱”的参数。我可以通过单击 iframe 中的任何链接来使用它,但这是不允许的,对吗?
谁能告诉我如何阻止用户点击该 iframe?
最佳答案
不幸的是,这不是 sandbox
属性所做的事情。其主要目的是限制子框架在浏览器上运行的能力(例如,阻止其加载到顶部浏览器框架的链接、显示弹出窗口、运行脚本等。)。限制用户可以使用框架执行的操作。
如果要阻止用户与框架交互,请考虑在框架顶部显示透明元素以防止其接收点击事件:
#frame-holder {
position: relative;
}
#frame-holder iframe {
width: 200px;
height: 100px;
box-sizing: border-box;
}
#frame-holder div {
position: absolute;
width: 200px;
height: 100px;
z-index: 1;
}
<div id="frame-holder">
<div></div>
<iframe sandbox src="http://example.com/"></iframe>
</div>
关于javascript - Google Chrome - 用于禁用超链接提交的 iframe 沙箱不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29981363/