iFrame调用父函数 [英] IFrame call parent function

查看:88
本文介绍了iFrame调用父函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iframe是否可以调用父级的函数,即使它们不在同一个域中? 当它们不在同一域中时,我的实际方法会产生一个安全错误:

is it possible for an iframe to call a parent's function, even if they are not in the same domain? My actual approach lifts a security error when they are not on the same domain:

<script>
function test()
{ alert('wow');
}
</script>
<iframe src="...."></iframe>

在iframe中,我会这样做:

And inside the iframe i would do this:

<script> 
function fin() 
{ top.test(); } 
</script>

非常感谢:)

推荐答案

您不能直接调用该函数(由于 postMessage (如对这个问题),并有一个事件侦听器调用该函数作为响应.

You can't call the function directly (due to the same origin policy, but you can use postMessage (as described in an answer to this question) and have an event listener call that function in response.

如果您需要支持Internet Explorer 7,将会有点运气不好和更低.

You're going to be somewhat out of luck if you need to support Internet Explorer 7 and lower.

这篇关于iFrame调用父函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆