< iframe> javascript访问父DOM跨域? [英] <iframe> javascript access parent DOM across domains?

查看:87
本文介绍了< iframe> javascript访问父DOM跨域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我控制嵌入在来自其他网域的网页中的iframe的内容。有什么办法在我的iframe中的javascript更改父的DOM?



例如,我想让我的iframed脚本向父DOM添加一堆html元素。

编辑:存在一种名为 Fragment ID Messaging ,这可能是跨域iframe之间的沟通方式。



修改:此外,Firefox 3.5,Opera,Chrome(等)似乎采用了html5 postMessageapi ,它允许在框架,iframe和弹出窗口之间进行安全的跨域数据传输。它像一个事件系统。显然,IE8支持此功能,这可能有点令人惊讶。



摘要:不,您不能直接访问/编辑DOM来自其他网域的网页。

解决方案

可以与您进行沟通, p> Hate说,但我是99%肯定是不是直接发生因为安全。



你可以尝试此处



bhh


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?

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?

Edit: There exists a technique called "Fragment ID Messaging" which might be a way to communicate between cross-domain iframes.

Edit: 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.

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.

解决方案

Hate to say it but I'm like 99% sure that ain't happening directly because of security.

You can try it out here.

bhh

这篇关于< iframe> javascript访问父DOM跨域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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