javascript iframe 中拒绝跨域访问权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4030220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:13:24  来源:igfitidea点击:

Cross domain access permission denied in iframe

javascripthtmliframeoutlookcross-domain

提问by R_Dhorawat

I am trying to embed OWA (Microsoft Exchange Server 2010) in a web page within an iframebut I get a JavaScript error on the OWA page saying Access Denied and then none of the controls within the OWA window work.

我正在尝试将 OWA (Microsoft Exchange Server 2010) 嵌入到一个网页中,iframe但我在 OWA 页面上收到一个 JavaScript 错误,提示访问被拒绝,然后 OWA 窗口中的所有控件都不起作用。

I have to use OWA in web page, I read in the form that cross domain does not work properly. Error comes as:

我必须在网页中使用 OWA,我以跨域无法正常工作的形式阅读。错误如下:

Client Information

User Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 GTB7.1 (.NET CLR 3.5.30729)
CPU Class:undefined
Platform:Win32
System Language:undefined
User Language:en-US
CookieEnabled:true

Exception Details

Date:Wed Oct 27 2010 10:17:05 GMT+0530 (India Standard Time)
Message:Permission denied for <http://domain_2>to get property HTMLIFrameElement.ownerDocumentfrom <domain_1>.
Url:http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js
Line:1

Call Stack

undefinedError()@:0 window$onerror(&quot;Permission denied for <http://domain_2> to get property HTMLIFrameElement.ownerDocument from <domain_1>.&quot;,&quot;http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js&quot;,1)@http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js:1 (domain_1>.&quot;,&quot;http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js&quot;,1%29@http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js:1) function Array$get_Length() { return this.length; } function Array$get_Item(index) { return this[index]; } function Array$get_Enumerator() { return new (Owa.Collections.ListEnumerator)(this); } function Array$remove(oItem) { var index = this.indexOf(oItem); if (index > -1) { this.splice(index, 1); } return index > -1; } function Array$removeAt(iIndex) { if (iIndex < this.length) { this.splice(iIndex, 1); return true; } return false; } function Array$add(oItem) { this.push(oItem); } function Array$clone() {

客户信息

用户代理:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 GTB7.1 (.NET CLR 3.5.30729)
CPU 等级:undefined
平台:Win32
系统语言:undefined
用户语言:en-US
CookieEnabled:true

异常详情

日期:星期三2010年10月27日10时17分05秒GMT + 0530(印度标准时间)
消息:权限被拒绝为<http://domain_2>获得财产HTMLIFrameElement.ownerDocument<domain_1>
网址:http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js
行:1

调用栈

undefinedError()@:0 window$onerror(&quot;Permission denied for <http://domain_2> to get property HTMLIFrameElement.ownerDocument from <domain_1>.&quot;,&quot;http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js&quot;,1)@http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js:1 (domain_1>.&quot;,&quot;http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js&quot;,1%29@http://domain_2/owa/[email protected]/14.0.639.21/scripts/premium/uglobal.js:1) function Array$get_Length() { return this.length; } function Array$get_Item(index) { return this[index]; } function Array$get_Enumerator() { return new (Owa.Collections.ListEnumerator)(this); } function Array$remove(oItem) { var index = this.indexOf(oItem); if (index > -1) { this.splice(index, 1); } return index > -1; } function Array$removeAt(iIndex) { if (iIndex < this.length) { this.splice(iIndex, 1); return true; } return false; } function Array$add(oItem) { this.push(oItem); } function Array$clone() {

What I saw is that the error comes when uglobal.jswhich comes with the Exchange in the iframetrying to access property of parent.

我看到的是,当uglobal.jsExchangeiframe尝试访问parent.

Message:Permission denied for <http://domain_2>to get property HTMLIFrameElement.ownerDocument from <domain_1>.

消息:<http://domain_2>从 获取属性 HTMLIFrameElement.ownerDocument 的权限被拒绝<domain_1>

Is there any other way by which I can use OWA in my page?

有没有其他方法可以在我的页面中使用 OWA?

回答by Sasha

That's the cross domain policy restricting you. It's designed to prevent cross site scripting (XSS) attacks.

这是限制您的跨域策略。它旨在防止跨站点脚本 (XSS) 攻击。

Basically, only pages from the same domain, protocol and port can alter each other's content.

基本上,只有来自相同域、协议和端口的页面才能更改彼此的内容。

回答by Philar

I faced similar issues when trying to make cross domain calls. For IE8 you can use the following approach

我在尝试进行跨域调用时遇到了类似的问题。对于 IE8,您可以使用以下方法

var xdr = new XDomainRequest();
xdr.open("get", "http://domain2");
xdr.onload = function(){
    //your code
};
xdr.send();

Additionally in IE only for testing purposes there is an option to add the specific address (domain1 in your case) to the trusted list Tools>Security>Trusted Sites>Sitesand allow it to make cross domain requests by going to custom leveland selecting Access data sources across domains. Please ensure the second is used only for testing.

此外,在 IE 中仅用于测试目的,有一个选项可以将特定地址(在您的情况下为 domain1)添加到受信任列表,Tools>Security>Trusted Sites>Sites并允许它通过转到custom level并选择Access data sources across domains. 请确保第二个仅用于测试。

回答by alex

If no JSONP solution exists, build a server side proxy.

如果不存在 JSONP 解决方案,请构建服务器端代理。