Access iframe window object within parent DOM

2019-04-10 10:26发布

I have project in which I have an elements from other domains. I'm using JavaScript to access first iframe window object into variable. Here is code :

var iframes = window.frames;

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

ifrWindow.postMessage("hello",IframeDomain);

I'm getting 'Permission denied' only for IE8. I have no problems with Chrome, Firefox, Safari or later versions IE11, etc..

Anyone has experienced this kind of issue with IE8?

2条回答
叛逆
2楼-- · 2019-04-10 10:47

Have you tried contentWindow or contentDocument method?

Something like this should work:

var iframe = document.getElementById("myframe");
var iframeWindow = (iframe.contentWindow || iframe.contentDocument);
查看更多
Deceive 欺骗
3楼-- · 2019-04-10 10:49

Try out this function for IE8

function iE8(){
        // use only for ie
        if (!jQuery.support.leadingWhitespace){
                //do something if it's IE8
        }
    }
查看更多
登录 后发表回答