2014-12-08 37 views
4

我有一個項目,其中有來自其他域的元素。我正在使用JavaScript將第一個iframe窗口對象存入變量。這裏是代碼:在父DOM中訪問iframe窗口對象

var iframes = window.frames; 

//grab first iframe 
var ifrWindow = iframes[0].window; // Here is where I get **Permision denied** 

ifrWindow.postMessage("hello",IframeDomain); 

我得到'權限被拒絕'只爲IE8。我對Chrome,Firefox,Safari或更高版本IE11等沒有任何問題。

任何人都遇到過這種問題與IE8?

+0

確實contentWindow工作,而不是僅僅窗口? – dandavis 2014-12-08 05:16:19

+0

謝謝danavis! contentWindow適用於IE8! – SlowCoder 2014-12-08 05:36:49

回答

3

您是否嘗試過contentWindow或contentDocument方法?

像這樣的東西應該工作:

var iframe = document.getElementById("myframe"); 
var iframeWindow = (iframe.contentWindow || iframe.contentDocument); 
0

嘗試這個功能IE8

function iE8(){ 
     // use only for ie 
     if (!jQuery.support.leadingWhitespace){ 
       //do something if it's IE8 
     } 
    }