Uncaught SecurityError: Blocked a frame with origin ... from accessing a frame with origin

Uncaught SecurityError: Blocked a frame with origin ... from accessing a frame with origin

我已经为通过 iframe 嵌入到报表中的 SAP 解决方案(无论什么)制作了一个组件。在 SAP 平台 (BO) 上部署报告后,出现此错误(在 Chrome 上,但在 IE 或 FF 上也不起作用):

Uncaught SecurityError: Blocked a frame with origin "http://support.domain.com" from accessing a frame with origin "http://support.domain.com". The frame requesting access set "document.domain" to "domain.com", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access.

iframe 已嵌入到我的组件中,因此它应该 运行 在同一域中使用与报告相同的端口。

我找到了这个 post on SO and this one,但它并没有真正帮助我理解我需要做什么。

有没有办法摆脱这个问题,或者至少解决这个问题? 谢谢 :).

编辑:

主页URL:http://support.domain.com/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=AbmffWLjCAlFsLj14TjuDWg

文件的

URL 在 iframe 上调用 属性(并生成错误):http://support.domain.com/BOE/OpenDocument/1411281523/zenwebclient/zen/mimes/sdk_include/com.domain.ds.extension/res/cmp/js/component.js

URL 的框架: http://support.domain.com/BOE/OpenDocument/1411281523/zenwebclient/zen/mimes/sdk_include/com.domain.ds.extension/res/cmp/js/map/js/map.html

iframe 本身嵌入了一些脚本标签,我可以在控制台的网络标签中看到一切正常加载。

也许能帮上忙。

编辑 2:

我刚刚意识到 SAP 报告本身嵌入到 iframe 中。这意味着我的 iframe 在 iframe 中,这可能是问题所在。尽管如此,当从 Eclipse 启动报告时,一切正常。

我终于找到了解决办法。

我的 iframe 顶部有一个 domain.location 设置为 domain.com 而我的 iframe 有一个 domain.location 设置为 support.domain.com.

尽管我仍然认为两者属于同一个域,但浏览器似乎不喜欢它。

重新设置 domain.location 完成了工作。

为了回答有关如何重新设置 location.domain 的问题,这里是我的团队过去使用的代码片段。这是很旧的(2 年前),没有真正优化,我们不再使用它,但我想它值得分享。 基本上,我们所做的是加载 iframe 并在 URL 参数中传递顶级域。

var topDomain = (function handleDomain(parameters) {
        if (typeof parameters === "undefined") {
            return;
        }
        parameters = parameters.split("&");
        var parameter  = [],
            domain;
        for (var i = 0; i<parameters.length; ++i) {
            parameter.push(parameters[i]);
        }
        for (var j = 0; j<parameter.length; ++j) {
            if (parameter[j].indexOf("domain") > -1) {
                domain = parameter[j];
                break;
            }
        }
        if (typeof domain !== "undefined") {
            domain = domain.split("=");
            return domain[1];
        }
        return; 
    })(window.location.search),
    domain = document.domain;

if (domain.indexOf(topDomain) > -1 && domain !== topDomain) {
    document.domain = topDomain;
}

之前的答案不再有效:

Document.domain - https://developer.mozilla.org/en-US/docs/Web/API/Document/domain Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

当前的解决方案是使用消息交换。请参阅以下样本: 解决方案是https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage