document.domain 在 JS 中破坏了 Sitecore 页面编辑器

document.domain in JS breaks Sitecore Page Editor

我有一个 Sitecore 站点,我需要在其中实施一个 iframe 通信解决方案,该解决方案要求我在父页面 (sitecore) 和子页面 (外部托管在子域上)。

如果我将 document.domain = "mydomain.com" 放在我网站的任何位置的 JS 中,Sitecore 中的页面编辑器和预览都会开始抛出 JS 错误,例如五彩纸屑,并且大多数功能都损坏了。当我删除它时,一切都会恢复正常。很奇怪。

关于为什么会发生这种情况以及我们如何解决它有什么想法吗?谢谢。

根据 https://developer.mozilla.org/en-US/docs/Web/API/document.domain,您只能将 document.domain 设置为当前站点的 "superdomain",因此任何跨域恶作剧都不起作用。我没有看到你正在使用的域,所以在不知道的情况下,我只能在这里猜测。

如果您确实想进行跨域通信,您可以 window.postMessage 试一试 https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage