(1)在父 frame 中调用子 iframe 中的 JS 方法,例如:调用 iframe 名称为 iframe1 中的 show() 方法,如下:
// 方式一:其中 iframe1 为 iframe 的名称 iframe1.window.show(); // 方式二:其中 iframe1 为 iframe 的名称 window.frames['iframe1'].window.show(); // 方式三:其中 iframe1 为 iframe 的名称 window.frames['iframe1'].show();
(2)在父 frame 中设置子 iframe 中的元素的样式,例如:设置 iframe 名称为 iframe1 中 div 元素的背景颜色为红色,如下:
// 方式一:其中 iframe1 为 iframe 的名称 iframe1.document.getElementById("div").style.background="red"; // 方式二:其中 iframe1 为 iframe 的名称 window.frames['iframe1'].document.getElementById("div").style.background="red";
(1)子 iframe 调用父 iframe 中的 show() 方法,如下:
// window.parent 表示父 iframe 中的 window 对象 window.parent.show();
(2)子 iframe 设置父 iframe 中元素 ID 为 h1 的背景颜色为红色,如下:
// window.parent 表示父 iframe 中的 window 对象 // window.parent.document 表示父 iframe 中的 document 对象 window.parent.document.getElementById("h1").style.background = "red";