首页 技术 正文
技术 2022年11月15日
0 收藏 905 点赞 2,470 浏览 1162 个字

今天做公司的内部流程系统,发现一问题。怎么调用iframe外面的方法呢?于是百度了一下,呵呵,把搜索结果摘抄下来。

转自:http://hi.baidu.com/zh_m_zhou/blog/item/e79d56d4daa2eecd50da4b24.html
作者:pocky

说明:假设有2个页面,index.html和inner.html。其中index.html中有一个iframe,这个iframe的src指向inner.html。
我们现在要做的就是:
1.在index.html中调用inner.html上的一个js方法
2.在inner.html中调用index.html上的一个js方法

实现代码如下:

index.html

1.<html>
2.<head>
3.<script type=”text/javascript”>
4.function ff(){
5.alert(“>>this is index’s js function”);
6.}
7.</script>
8.</head>
9.<body>
10.<div style=”background: lightblue;”>
11.This is index page.
12.<input type=”button” value=”run index’s function” onclick=”ff();” />
13.<input type=”button” value=”run inner page’s function” onclick=’window.frames[“childPage”].ff();’ />
14.</div>
15.<iframe id=”childPage” name=”childPage” src=”inner.html” width=”100%” frameborder=”0″></iframe>
16.</body>
17.</html>

inner.html

1.<html>
2.<head>
3.<script type=”text/javascript”>
4.function ff(){
5.alert(“>>this is inner page’s js function”);
6.}
7.</script>
8.</head>
9.<body>
10.<div style=”background: lightgreen;”>
11.This is inner page.
12.<input type=”button” value=”run index’s function” onclick=’parent.window.ff();’ />
13.<input type=”button” value=”run inner page’s function” onclick=”ff();” />
14.</div>
15.</body>
16.</html>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781