iframe 获取变量
父获取子
<iframe src="son.html" id="iframe" name="iframe"></iframe>
let iframe = window.parent.document.getElementById('iframe');
let iframeWindow =
window.parent.document.getElementById('iframe').contentWindow;
let iframeDocument =
window.parent.document.getElementById('iframe').contentWindow.document;
let sonWindow = window.parent.document.getElementById('iframe').contentWindow;
setTimeout(() => {
console.log(sonWindow.sonObj);
}, 100);
window.fatherObj = '父页面变量';
子获取父
window.sonObj = '子页面变量';
let fatherIframe = window.parent;
setTimeout(() => {
console.log(fatherIframe.fatherObj);
}, 100);