如何防止 iframe 访问父窗口,但允许父窗口访问 iframe 文档
How to prevent iframe from accessing parent window but allow parent window to access iframe document?
基本上,我想要这样的东西(它是ES6):
<iframe id="iframe"></iframe>
<script>
var iframeDoc = document.getElementById('iframe').contentDocument;
iframeDoc.open('text/html', 'replace');
iframeDoc.write(`
<!doctype html>
<html>
<body>
<script>
// do not allow window.parent access!
alert(window.parent.document.cookie);
<'/script>
</body>
</html>
`);
iframeDoc.close();
</script>
警报框显示父窗口的 Cookie,这是错误的。我希望iframe执行自己的沙盒javascript代码。这在HTML5中可能吗?
我已经尝试了sandbox
属性及其值的所有排列。
也许可以将 iframe 及其内容构造为 src
属性的数据 URI,但这似乎有点笨拙。(或者也许不是?URI 长度没有限制吗?
你试过使用 sandbox
吗?
W3C 有很好的文档,它将阻止顶级浏览上下文。
http://www.w3schools.com/tags/att_iframe_sandbox.asp
另请查看本教程:
http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/
相关文章:
- 在Twitter上用ie9中的空白src访问iframe的contentWindow
- 访问iframe内部的jqgrid
- 如何从CasperJS访问iframe
- 访问iframe函数
- IE9”;访问被拒绝”;访问IFrame时出错
- 访问 iframe 外部的元素
- 检查JS是否可以访问iframe的文档
- 访问iframe中的facebook页面被拒绝
- Internet Explorer:可以't访问IFrame内容,除非状态代码为200
- 我如何访问 iframe 中 URL 的参数
- 如何访问 iframe.contentDocument 以在跨源请求后获得响应
- 通过jquery/javascript访问iframe元素
- 如何从另一个域访问 iframe 的元素
- 如何访问iframe's来自用户脚本的javascript
- Chrome扩展-访问iframe元素
- 如何在 AngularJS 中通过 id 访问 iframe
- 使用 JavaScript 访问 iframe 和 body Tag 中的元素
- 如何从父文档访问 iframe 中的元素
- 如何在弹出窗口中访问 iframe.html在 chrome 扩展程序中
- 如何防止 iframe 访问父窗口,但允许父窗口访问 iframe 文档