2015-09-07 92 views
12

在Android 4.4及更高版本的设备中会出现以下问题。iframe的安全错误

这是我们的iframe的样子:

<iframe frameborder=0 id="myIFRAME"></iframe> 

以下是我们编程变得IFRAME方式:

if(document.getElementById("myIFRAME")){ 
     me.setMyIFRAME(document.getElementById("myIFRAME").contentWindow); 
} 

这导致相关协议不匹配安全错误:

"Uncaught SecurityError: Blocked a frame with origin " https://www.google.com " from accessing a frame with origin "file://". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "file". Protocols must match.

我们正在使用煎茶触摸与科尔多瓦发展我们的项目。

回答

0

原来的iframe被加载其访问window.document这是导致跨域安全错误 下面,如果条件是页面中的HTML页面

if (window.parent.document != window.document) 

我们将其更改为在解决安全错误的情况下

if (window.parent != window) 
+0

我必须使用这个 – Vishnu

4

Cordova security guide说:

If content is served in an iframe from a whitelisted domain, that domain will have access to the native Cordova bridge.

您是否尝试过加入外部域to the whitelist内​​3210?

<access origin="https://google.com" /> 
+0

我已经试过设置this.But也没有帮助 – Ritika

0

@Ritika,
我在这里瞎猜,因为我不使用iframe的,但在你的元素我没有看到一个src。因此,系统将其设置为某种类型的默认设置,并且该来源的协议为file://

我认为如果您设置src=即使是空白的,问题也会消失。

离开,只是一个猜测。好运。

+0

SRC在代码动态创建&然后最终上iframe.Even设置我试图设置SRC =“”最初,但是这并不有助于 – Ritika

+0

好的,在黑暗中拍摄。你使用* white-list *,插件和CSP? – JesseMonroy650

+0

我已经尝试使用whie-列表,这也不帮 – Ritika

0
  1. Google无法通过iFrame访问。

  2. 从服务使用file://协议的页面不能通过http://https://协议默认访问资源。