javascript - 如何在沙盒 iframe 上允许 document.domain?
问题描述
我有一个这样定义的沙盒 iframe:
<iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals" src="...">
</iframe>
当我document.domain
在 iframe 中设置时,出现以下错误:
Uncaught DOMException: Failed to set the 'domain' property on 'Document': Assignment is forbidden for sandboxed iframes.
如何允许在 iframe 中设置 document.domain?
解决方案
(感谢评论回答我自己的问题)
由于您愿意将 document.domain 设置为允许在 to 上下文之间进行访问,这完全违背了沙箱的目的。因此,首先对 iframe 进行沙盒处理是没有意义的。
推荐阅读
- c# - 我们如何确定某个包是否适用于 .NET Core 3.1?
- .net - 带有 IconPacks 图标的 MahApps HamburgerMenu
- javascript - 使用 MomentJS 转换日期时遇到问题
- java - 附加到新的 StringBuilder 输出时使用 %d 保持双重格式
- android-fragments - 带有导航图和 1 个活动应用程序的 Kotlin FCM 推送通知
- javascript - 是否可以从弹出面板中修剪文本区域中的文本?
- java - 来自不同类的静态变量的问题
- python - 如何在 tkinter 中将文本标签居中?
- plot - Seaborn regplot y_test 和预测的样本量
- c# - 使用 Bot Framework v4,我如何确定 OAuthPrompt 是刚刚登录还是令牌已经存在?