1, 获取页面上的 iframe
1-1, document.getElementById('iframeId');
1-2, Windows.frames[0],Windows.frames['frameName'],frames['frameName'],frames[0],self.frames[0], 此处 self 与 Windows 等价, 相当于本页面的 Windows 对象.
1-3, contentWindow,contentDocument 两个属性, 也是可以用来获取子窗口,
contentWindow 兼容各个浏览器, 可取得子窗口的 Windows 对象.
contentDocument Firefox 支持,> ie8 的 IE 支持. 可取得子窗口的 document 对象.
2, 子页面访问父页面元素:
parent.document.getElementById('id') 和 document 相关的方法都可以这样用 ;
3, 父页面访问子页面元素:
document.getElementById('iframeId').contentWindow.document.getElementById("id"); contentWindow 后跟 document 相关方法
Windows.frames[0].contentWindow.document.getElementById("id");
4, 子页面访问父页面变量:
parent.a; 或者调用 父页面有返回值的函数解决.
5, 父页面访问子页面变量:
父页面声明全局变量, 子页面复制修改; 或者调用子页面有返回值的函数解决.
frames[0].a;
6, 子页面访问父页面方法:
Windows.parent.parentMethod();
7, 父页面访问子页面方法:
- document.getElementById('iframeId').contentWindow.iframeMethod();
- frames[0].iframeMethod();
8, 兄弟框架之间调用:
- self.parent.frames['child1'];
- self.parent.frames['child2'];
9, 多层框架的调用:
- Windows.frames[0].frames[2];
- Windows.frames['child_1'].frames['sub_child_3'];
来源: http://www.bubuko.com/infodetail-2999171.html