可以使用JavaScript中的contentWindow属性来获取iframe的Window对象,然后使用parent属性来获取父级页面的Window对象,最后就可以在父级页面中访问和操作iframe中的节点了。

示例代码:

// 获取iframe元素
var iframe = document.getElementById('my-iframe');
// 获取iframe的Window对象
var iframeWindow = iframe.contentWindow;
// 获取父级页面的Window对象
var parentWindow = window.parent;
// 在父级页面中访问iframe中的节点
var iframeNode = iframeWindow.document.getElementById('my-iframe-node');
如何在父级html获取到iframe的节点

原文地址: https://www.cveoy.top/t/topic/hio7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录