2015-09-07 96 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://協議默認訪問資源。