读父文档的IFRAME和不断变化的父 [英] Reading parent document from iFrame and changing parent

查看:88
本文介绍了读父文档的IFRAME和不断变化的父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写这将加载一个按钮,在一个页面上的iFrame的一个JavaScript应用程序。此应用程序将读取父文件,并去掉所有的图像,使用最小的造型和重载父这一新标记的页面。

I'm trying to write a JavaScript application that will load a button up in an iFrame on a page. This application will read the parent document and strip out all images, apply minimal styling and reload the parent with this newly marked up page.

我遇到的问题是阅读和写作的iFrame的父文件。有谁知道的一种方式来实现这一目标?我读过了一个小的跨域消息,但我不能确定的替代品,哪些是最好的。

The problem I am having is reading and writing the parent document from the iFrame. Does anyone know of a way to achieve this? I've read up a little on cross-domain messaging but am unsure of the alternatives and which would be best.

在此先感谢。

推荐答案

您可以通过使用父母或使用总是指向最外层的文件顶部的变量引用父任。

You can reference the parent either by using parent or using the top variable that always point to the outer most document.

  • 父==父窗口
  • 在顶部==了大部分窗口

因此​​,对于accesing的第一个div父

So for accesing the first div in the parent

var d = parent.document.getElementByTagName("div")[0];

但正如评论指出,目前,无论是外部文档,并在iframe文档必须来自同一个域,否则你会被阻止出于安全原因。

But as noted already in the comment, both the outer document and the document in the iframe need to be from the same domain or you will be blocked for security reasons.

这篇关于读父文档的IFRAME和不断变化的父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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