Home  >  Article  >  Web Front-end  >  Javscript调用iframe框架页面中函数的方法_javascript技巧

Javscript调用iframe框架页面中函数的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:32:131293browse

本文实例讲述了在Javscript调用iframe框架页面中函数的方法,这个调用方法其实非常的简单,有了这个方法我们就可以实现iframe之间传值或修改值了,操作起来都非常的简单。分享给大家供大家参考。具体实现方法如下:

访问iframe里面的函数:

复制代码 代码如下:
document.getElementById('commentIframe').contentWindow.hasLogined();

commentIframe为iframe的id.
要在 window.onload里面执行

例子如下:

1.html

复制代码 代码如下:
aa

2.html 页面

复制代码 代码如下:

在1.htm中点击test按钮,可以使2.htm(iframe页面)中mybutton按钮失效.就这么简单,呵呵.如果要调用2.htm中的JS函数这样写:

复制代码 代码如下:
self.frames['a'].funtionname(param)

在1.htm中调用2.htm中的JS函数:iframe2.showInfo();

例子说明:

假设有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:

复制代码 代码如下:






This is index page.





inner.html:

复制代码 代码如下:






This is inner page.




希望本文所述对大家基于javascript的web程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn