Iframe父页面与子页面之间的相互调用
来源:互联网 发布:淘宝改后台软件安全吗 编辑:程序博客网 时间:2024/05/17 08:59
iframe元素就是文档中的文档。
window对象: 浏览器会在其打开一个HTML文档时创建一个对应的window对象。但是,如果一个文档定义了一个或者多个框架(即:包含一个或者多个frame或者iframe标签),浏览器就会为原始文档创建一个window对象,再为每个iframe创建额外的window对象,这些额外的window对象是原始窗口的子窗口。
contentWindow: 是指指定的iframe或者iframe所在的window对象
Demo1
父页面fu.html:
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>父页面</title> </head> <body> <input type=button value="调用子页面中的函数childSay函数" onclick="callChild()"> <iframe id="myFrame" src="zi.html"></iframe> <script type="text/javascript">function parentSay() {alert("我是父页面中的方法");}function callChild(){document.getElementById("myFrame").contentWindow.childSay();} </script> </body></html>
子页面zi.html
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>子页面</title> </head> <body> <input type=button value="调用父页面中的parentSay()函数" onclick="callParent()"> <script type="text/javascript">function childSay(){alert("我是子页面的say方法");}function callParent() {parent.parentSay();} </script> </body></html>
Demo2
父页面iframe1.html:
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>父页面与子页面之间的调用</title> </head> <body> <iframe src="http://localhost/iframe/iframe3.html" id="iframe3"></iframe> <iframe src="http://localhost/iframe/iframe2.html" id="iframe2"></iframe> <div class="iframe1">我是父页面</div> <script type="text/javascript"> var iframe2=document.getElementById('iframe2'); iframe2.onload=function(){//父页面调用子页面中的方法 iframe2.contentWindow.b(); }; function test2() { console.log("我是父页面中的方法,在子页面中调用的"); return iframe2; } </script> </body></html>
子页面iframe2.html:
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>子页面</title> </head> <body> <div id="test">aaa</div> <div class="iframe2">子页面</div> <script type="text/javascript"> //子页面iframe2.html调用父页面iframe1.html的函数: parent.test2(); function b(){ console.log("我是子页面iframe2"); } function c() { console.log("iframe3页面调用iframe2页面"); } </script> </body></html>
子页面iframe3.html:
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>iframe3</title> </head> <body> <script type="text/javascript"> var iframe2=parent.test2(); iframe2.contentWindow.c();//iframe3调用iframe2中的方法 </script> </body></html>
Demo2也实现了子页面与子页面之间相互调用。
我的新博客,请多多指教
0 0
- Iframe父页面与子页面之间的相互调用
- Iframe父页面与子页面之间的相互调用
- iframe 父页面与子页面之间的方法的相互调用
- iframe 父页面与子页面之间的方法、属性的相互调用
- iframe 父页面与子页面之间的方法的相互调用
- Iframe 父页面与子页面相互js调用实现
- 利用iframe引用网页后,父页面子页面之间的相互调用
- iframe的父页面、子页面相互调用
- iframe父页面与子页面之间的元素获取与方法调用
- iframe子父页面间js的相互调用
- iframe父页面与子页面之间的操作
- iframe页面与父页面函数之间的调用
- 子页面与父页面相互调用
- iframe页面中父页面跟子页面方法的相互调用
- js里父页面与子页面的相互调用
- js里父页面与子页面的相互调用
- js里父页面与子页面的相互调用
- js里父页面与子页面的相互调用
- Android-在动作栏中添加“设置图标”
- 什么是C++虚函数、虚函数的作用和使用方法
- AutoCompleteTextView的使用和源码分析以及实现响应式输入提示功能
- Fixing your iOS build scripts PackageApplication ERROR
- 选择支持向量机(SVM)核函数
- Iframe父页面与子页面之间的相互调用
- 10.1Android性能优化之布局优化
- 第七届蓝桥杯省赛C/C++B组省赛题解
- LeetCode 70 Climbing Stairs
- java第十一节-包装类,基本类型,String之间的转换
- 解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
- C++ 文件输入输出流
- 59.通过 runtime为Category添加属性与成员变量
- Installation ShadowSocks with Ubuntu 16.04 beta