iframe的一些操作(兼容大多数浏览器的做法)
- 在父页面中获取iframe的window对象
document.querySelector(iframe-class / iframe-id).contentWindow;
window.frames[iframeId]
window.frames[iframeName]
window.frames[iframeIndex]
iframeElement.contentWindow
- 在父页面中获取iframe的document对象
document.querySelector(iframe-class / iframe-id).contentDocument;
let _iframeWindow = document.querySelector(iframe-class / iframe-id).contentWindow.document;
document.querySelector(iframe-class / iframe-id).contentDocument || window.frames[iframeId].contentDocument;
- iframe页面获取父页面的window对象
parent: 父页面的window对象
top: 顶层页面的window对象
self: 始终指向当前页面的window对象