iframe中拒绝跨域访问权限

时间:2010-10-27 05:27:59

标签: javascript html iframe outlook cross-domain

我正在尝试将OWA(Microsoft Exchange Server 2010)嵌入到iframe内的网页中,但我在OWA页面上收到一条JavaScript错误,说“访问被拒绝”,然后OWA窗口中没有任何控件正常工作

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

  

客户信息

     

用户代理: 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>从[{1}}获取财产HTMLIFrameElement.ownerDocument的权限被拒绝。
  网址: <domain_1>
  行: 1

     

调用堆栈

http://domain_2/owa/testuser@exch2k10.com/14.0.639.21/scripts/premium/uglobal.js

我看到的是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/testuser@exch2k10.com/14.0.639.21/scripts/premium/uglobal.js&quot;,1)@http://domain_2/owa/testuser@exch2k10.com/14.0.639.21/scripts/premium/uglobal.js:1 (domain_1>.&quot;,&quot;http://domain_2/owa/testuser@exch2k10.com/14.0.639.21/scripts/premium/uglobal.js&quot;,1%29@http://domain_2/owa/testuser@exch2k10.com/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() { 试图访问uglobal.js的属性时,iframe附带的parent错误。

  

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

我可以在页面中使用OWA吗?

3 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:2)

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

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

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

答案 2 :(得分:1)

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