简体   繁体   中英

IFrame call parent function

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>

And inside the iframe i would do this:

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

Many thanks :)

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.

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

No, you can't. The same origin policy forbids this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM