最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript iFrame Limitations - Stack Overflow

programmeradmin0浏览0评论

I know that, for security reasons, javascript can't read the contents of an iframe if it belongs to a different domain. This makes sense, given that the entire page could be an iframe with snooping scripts outside of the frame.

The question is - are there equal limitations in the other direction? Can javascript within an iframe (from a different domain) read and manipulate the dom in its parent window?

Thanks!

I know that, for security reasons, javascript can't read the contents of an iframe if it belongs to a different domain. This makes sense, given that the entire page could be an iframe with snooping scripts outside of the frame.

The question is - are there equal limitations in the other direction? Can javascript within an iframe (from a different domain) read and manipulate the dom in its parent window?

Thanks!

Share Improve this question asked May 12, 2010 at 0:55 MatrymMatrym 17.1k35 gold badges99 silver badges141 bronze badges 1
  • The limitations are the same in both directions. – Sean Hogan Commented May 12, 2010 at 1:26
Add a ment  | 

2 Answers 2

Reset to default 8

You can't.
This would be a security hole. Now that everyone is crazy adding facebook iframes to their sites, imagine if javascript from FB could interact with your page ;)
Anyway, i set up a small example, and got the same origin warning when i tried to get a parent's div from inside the iframe (which was in another domain)

If you want to use this in a two domains that you own (not trying to attack anyone) you can do that using ajax as described Here.

发布评论

评论列表(0)

  1. 暂无评论