gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:19:49 24 4
gpt4 key购买 nike

我一直认为(当您有多个 iframe 时)window.frames[0] 代表第一个 iframe 的 DOM 元素。

但是根据Mozilla Developer Network ,这不是真的:

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 (i.e., window.frames[ 0 ] is the same thing as document.getElementsByTagName( "iframe" )[ 0 ].contentWindow).

在 JavaScript 中有没有办法从 window.frames[0] 到 iframe 的 DOM 元素?

最佳答案

frameElement 将返回嵌入了 iframe 的 DOM 元素。 https://developer.mozilla.org/en-US/docs/Web/API/Window/frameElement

例如:

var iframeElem = window.frames[0].frameElement

接下来,这应该验证:

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

关于javascript - 有没有办法从 window.frames[0] 获取 iframe dom 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com