Chrome: getting iFrame and pasting into body

I have the following code that works fine in Firefox ...

if (!iFrame) iFrame = outerDoc.getElementById('_dialog_iframe'); var iFrameDoc = iFrame.contentWindow.document; // get iframe doc 

and the version of Chrome ...

 if (!iFrame) iFrame = outerDoc.getElementById('_dialog_iframe'); var iFrameDoc = iFrame.document; // get iframe doc 

I test the code by getting iFrameDoc.body , when I run the FireFox code in Firefox, it works fine. However, the Chrome code returns undefined . What for? How to fix this so that it works fine in Chrome?

+3
javascript google-chrome google-chrome-extension iframe
source share
1 answer

If the iframe element has a document property in Chrome, then I am surprised and it is non-standard and not supported in other browsers. The standard property is contentDocument , but to support other browsers you can use contentWindow.document . The following will work in all major browsers:

 var iFrameDoc = iFrame.contentDocument || iFrame.contentWindow.document; 
+10
source share

All Articles