<iframe>javascript 跨域访问父DOM? [英] <iframe> javascript access parent DOM across domains?
问题描述
我控制嵌入在来自另一个域的页面中的 iframe 的内容.我的 iframe 中的 javascript 有什么方法可以更改父级的 DOM?
I control the content of an iframe which is embedded in a page from another domain. Is there any way for javascript in my iframe to make changes to the parent's DOM?
例如,我想让我的 iframe 脚本向父 DOM 添加一堆 html 元素.这似乎是一个很高的要求 - 想法?
For example, I would like to have my iframed script add a bunch of html elements to the parent DOM. This seems like a pretty tall order - thoughts?
有一种技术叫做Fragment ID Messaging" 这可能是跨域 iframe 之间通信的一种方式.
There exists a technique called "Fragment ID Messaging" which might be a way to communicate between cross-domain iframes.
此外,Firefox 3.5、Opera、Chrome(等)似乎正在采用 html5 "postMessage" api,它允许在框架、iframe 和弹出窗口之间进行安全的跨域数据传输.它的工作原理类似于事件系统.IE8 显然支持此功能,这可能有点令人惊讶.
Also, Firefox 3.5, Opera, Chrome (etc) seem to be adopting the html5 "postMessage" api, which allows secure, cross-domain data transmission between frames, iframes and popups. It works like an event system. IE8 supports this feature, apparently, which is perhaps a little surprising.
总结: 不可以,您不能直接从另一个域访问/编辑页面的 DOM.但是你可以与它沟通,它可以合作做出你想要的改变.
Summary: No, you can't directly access/edit the DOM of a page from another domain. But you can communicate with it, and it can co-operate to make the changes you want.
推荐答案
我不想这么说,但我 99% 肯定这不会直接发生,因为安全性.
Hate to say it but I'm like 99% sure that ain't happening directly because of security.
您可以在此处试用.
嘘
这篇关于<iframe>javascript 跨域访问父DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!