Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iframe #56

Open
whizbz11 opened this issue Jul 24, 2016 · 0 comments
Open

iframe #56

whizbz11 opened this issue Jul 24, 2016 · 0 comments

Comments

@whizbz11
Copy link
Member

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下可以省略。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant