Uncaught SecurityError:阻止具有原点的帧...访问具有原点的帧 [英] Uncaught SecurityError: Blocked a frame with origin ... from accessing a frame with origin

查看:347
本文介绍了Uncaught SecurityError:阻止具有原点的帧...访问具有原点的帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've made a component for an SAP solution (whatever) that is embedded into a report through an iframe. After I deployed the report on an SAP plateform (BO), I got this error (on Chrome, but does not work on IE or FF either):

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嵌入到我的组件中,因此它假设在与报告相同的端口的同一域上运行。

The iframe is embedded into my component so it's suppose to run on the same domain with same port than report.

我发现这是帖子 one ,但它并没有真正帮助我理解我需要做什么。

I found this post on SO and this one, but it does not really helped me to understand what I need to do.

是否有摆脱这个,或至少解决这个问题的方法?
谢谢:)。

Is there a way to get rid of this, or at least work around this ? Thanks :).

编辑:

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

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

URL of the file calling a property on the iframe (and generating the error) : http://support.domain.com/BOE/OpenDocument/1411281523/zenwebclient/zen/mimes/sdk_include/com.domain.ds.extension/res/cmp/js/component.js

框架的网址:
http:// s upport.domain.com/BOE/OpenDocument/1411281523/zenwebclient/zen/mimes/sdk_include/com.domain.ds.extension/res/cmp/js/map/js/map.html

iframe嵌入了一些脚本标签,我可以看到控制台网络标签中的所有内容都正常加载。

The iframe embed itself some script tag, I can see everything loading fine in the Network tag of the console.

也许它可以帮助。

编辑2:

我刚刚意识到SAP报告本身是嵌入的进入iframe。这意味着我的iframe在iframe中,这可能是问题所在。但是,当从Eclipse推出报告时,一切正常。

I just realized SAP report is itself embedded into an iframe. That means my iframe is within an iframe, that might be the issue. Still, when lauching the report from Eclipse, everything is working.

推荐答案

我终于找到了解决方案。

I've finally found a solution.

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

The top of my iframe had a domain.location set to domain.com and my iframe a domain.location set to support.domain.com.

事件虽然我仍然认为两者都属于同一个域,浏览器似乎不喜欢它。

Event though I still think that both belong to the same domain, browsers don't like it it seems so.

重新设置 domain.location 做了

要回答有关如何重新设置 location.domain 的问题,请参阅以下内容:我的团队曾经使用的代码。这是相当古老的(2年前),没有真正优化,我们不再使用它,但我想这值得分享。
基本上,我们正在做的是加载 iframe 并在URL参数中传递顶级域名。

To answer the ones asking about how to re-set location.domain, here is the snippet of code my team used to use. This is quite old (2y ago), not really optimized and we do not use it anymore, but I guess it's worth sharing. Basically, what we were doing is load the iframe with passing it top domain in the URL parameters.

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;
}

这篇关于Uncaught SecurityError:阻止具有原点的帧...访问具有原点的帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆