2016-07-05 173 views
0

我收到以下錯誤,試圖讀取iframe中的內容,它的src爲其他域IFRAME同源策略的問題

SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://qa-xxx.abc.com" from accessing a frame with origin "https://yyy.abc.com". Protocols, domains, and ports must match. 

現在假設現在我在https://qa-xxx.abc.com doamin和我的iframe代碼

<iframe src="https://yyy.abc.com" style="height: 100%; width: 105%;" id="id_description_iframe"></iframe> 

,而搜索,我發現這個解決方案Access-Control-Allow-Origin not working for iframe withing the same domain

所以我做了這樣的document.domain = 'abc.com'

同樣的問題,任何解決方案將是有益的。

+0

如果您不控制iframe中的代碼,您不能在其中執行任何操作。你是否同時控制? – charlietfl

+0

@charlietfl我沒有找到你,iframe的代碼控制是什麼意思 – user3106347

+0

簡單...是你控制的域名上的iframe,你可以將代碼放入該頁面? – charlietfl

回答

0

您違反了同源策略。向兩個頁面添加: document.domain = abc.com 。直接在腳本標記中,或者在被引用的js文件中。