【发布时间】:2016-02-27 06:28:43
【问题描述】:
基本上,我想要这样的东西(它是 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,但这似乎有点 hacky。 (或者可能没有?URI长度没有限制吗?)
【问题讨论】:
标签: javascript iframe