admin管理员组文章数量:1332345
Consider a page that contains an iframe. The iframe source is on another domain.
I'd be interested in 2 things:
Can I create an event listener inside the iframe that listens to events that take place in the parent window (and runs a function in the iframe)?
Can I create an event listener inside the parent window that listens to events that take place in the iframe (and runs a function in the parent window)?
Consider a page that contains an iframe. The iframe source is on another domain.
I'd be interested in 2 things:
Can I create an event listener inside the iframe that listens to events that take place in the parent window (and runs a function in the iframe)?
Can I create an event listener inside the parent window that listens to events that take place in the iframe (and runs a function in the parent window)?
2 Answers
Reset to default 3That's a no on both accounts, cross-domain scripting security measures disallow any cross domain munication.
You might want to take a look at this indepth article about Cross-Domain Communication with IFrames. It talks about what you can and can't do, and provides some alternatives like window.postMessage
Yes. But it might be more work than you're interested in. You'll need to create a proxy for that page that lives on the same domain as the parent page. Your proxy could be a simple pass-through, but it could very well break the page; some URL-rewriting might be required in order to not break scripts that run on that page that assume things about the context it's being evaluated in, so on that front "it depends."
But your question is "Can you ...?" and the answer is "Yes."
本文标签: javascriptAbout iframes and event listenersStack Overflow
版权声明:本文标题:javascript - About iframes and event listeners - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742327154a2453951.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论