iuap-design / blog

📖 用友网络大前端技术团队博客

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iframe

whizbz11 opened this issue · comments

commented

iframe中父子页面互掉javascript函数的方法

iframe子页面调用 父页面js函数

子页面调用父页面函数只需要写上window.praent就可以了。比如调用a()函数,就写成:

window.parent.a();

但是我在chrome浏览器下却发现此方法无效了!查了半天才了解,在chrome 5+中,window.parent无法在file://协议中运行,但是发布了之后http://协议下是可以运行的。此方法支持ie、firefox浏览器。

iframe父页面调用 子页面js函数

这个就稍微复杂一些,下面的方法支持ie和firefox浏览器:

document.getElementById('iframeID').contentWindow.b();

注:iframeID是iframe框架的id,b()为子页面js函数。contentWindow属性是指定的frame或者iframe所在的window对象,IE下可以省略。