Access to the iframe object window in the parent DOM

I have a project in which I have items from other domains. I use JavaScript to access the first iframe object in a variable. Here is the 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 get "Permission denied" for IE8 only. I have no problem with Chrome, Firefox, Safari or later versions of IE11 etc.

Has anyone encountered such a problem in IE8?

+4
source share
2 answers

Have you tried the contentWindow or contentDocument method?

Something like this should work:

var iframe = document.getElementById("myframe");
var iframeWindow = (iframe.contentWindow || iframe.contentDocument);
+4
source

Try this feature for IE8

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

All Articles