简体   繁体   English

有没有办法从window.frames [0]获取iframe dom元素

[英]Is there a way to get the iframe dom element from window.frames[0]

I always thought (when you have several iframes), that window.frames[0] represents the DOM element of the first iframe. 我一直认为(当你有几个iframe时), window.frames[0]代表第一个iframe的DOM元素。

But according to the Mozilla Developer Network , this isn't true: 但根据Mozilla开发者网络 ,这不是真的:

Each item in the window.frames pseudo-array represents the window object corresponding to the given 's or 's content, not the (i)frame DOM element (ie, window.frames[ 0 ] is the same thing as document.getElementsByTagName( "iframe" )[ 0 ].contentWindow) . window.frames伪数组中的每个项表示与给定的内容相对应的窗口对象,而不是(i)帧DOM元素(即, window.frames[ 0 ]document.getElementsByTagName( "iframe" )[ 0 ].contentWindow)相同。 document.getElementsByTagName( "iframe" )[ 0 ].contentWindow)

Is there a way in JavaScript to get from window.frames[0] to the DOM element of the iframe? JavaScript中有没有办法从window.frames[0]到iframe的DOM元素?

frameElement will return the DOM element in which the iframe is embedded. frameElement将返回嵌入iframe的DOM元素。 https://developer.mozilla.org/en-US/docs/Web/API/Window/frameElement https://developer.mozilla.org/en-US/docs/Web/API/Window/frameElement

For example: 例如:

var iframeElem = window.frames[0].frameElement

Following, this should validate: 以下,这应验证:

window.frames[0].frameElement.ownerDocument.defaultView.frames[0] == frames[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM