开发者

iframe.contentWindow.document Chrome alternative?

开发者 https://www.devze.com 2023-02-11 03:38 出处:网络
How would I call the following in Chrome? 开发者_Go百科iframe.contentWindow.documentChrome does in fact support iframe.contentWindow.document, but there\'s a little wrinkle that you\'ve probably falle

How would I call the following in Chrome? 开发者_Go百科iframe.contentWindow.document


Chrome does in fact support iframe.contentWindow.document, but there's a little wrinkle that you've probably fallen prey to: if the file set to the iframe.src property is being accessed locally (i.e. using the "file://" protocol), that property is inaccessible in Chrome. This will happen if you specify a relative file address and attempt to test the script without using a web-server like IIS or Apache (by simply double-clicking it). The same also applies to iframe.contentDocument.

I ran into a similar problem where, for some odd reason, Chrome would not accept event handlers dynamically attached to iframes. Then I found the note in this article, tested with Apache, and hey presto, it suddenly began to work.


iframe.contentDocument is what you want.

See also Chrome: Getting iFrame and inserting into body


<iframe id="popupFrame" />

<script type="text/javascript">
var popupFrame = document.getElementById('popupFrame');
var iFrameDoc;
if (switchAccountsPopupFrame.document) {
    iFrameDoc = switchAccountsPopupFrame.document; // works with IE9 and FF9
}
else {
    // Google Chrome (16.0.912.75 m)
    iFrameDoc = switchAccountsPopupFrame.ownerDocument;
}
....
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号