【问题标题】:How can I allow document.domain on a sandboxed iframe?如何在沙盒 iframe 上允许 document.domain?
【发布时间】:2021-03-02 06:30:48
【问题描述】:

我有一个这样定义的沙盒 iframe:

<iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals" src="...">
</iframe>

当我在 iframe 中设置 document.domain 时,我收到以下错误:

Uncaught DOMException: Failed to set the 'domain' property on 'Document': Assignment is forbidden for sandboxed iframes.

如何允许在 iframe 中设置 document.domain?

【问题讨论】:

标签: javascript html


【解决方案1】:

(感谢 cmets 回答我自己的问题)

由于您愿意将 document.domain 设置为允许在 to 上下文之间进行访问,这完全违背了沙盒的目的。因此,首先对 iframe 进行沙盒处理是没有意义的。

【讨论】:

    猜你喜欢
    • 2015-09-19
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 2013-04-17
    • 1970-01-01
    • 2014-03-06
    • 2019-10-24
    相关资源
    最近更新 更多