从iframe访问父窗口(跨域) [英] Access parent window from iframe (cross-domain)

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

问题描述

如果iFrame中的窗口是从另一个域加载的,我遇到了从iFrame访问父窗口的任务。如果我理解正确,所有现代浏览器现在允许这样做。所以我在这里找到最好的解决方案。



我要以下一种方式完成:



我有一个iFrame的覆盖层。这将工作,而不是弹出窗口,以防止弹出窗口阻止程序阻止我的内容。任务是当iFrame中的文档完成一些工作时重新加载主页面。
在将被加载到iFrame的文档中,我将添加

 < div id =is_closed class =false>< / div> 

在父窗口中,我将添加函数,它将每秒调用,并检查这个div仍然有类名false。如果这将更改为true,我将调用一些回调。



如果您有任何更好的解决方案,请与我共享。将感谢任何帮助。



编辑:这是不可能的,因为它不仅不可能从子窗口操作父窗口,反之亦然。我的想法是从父窗口操作子窗口。我错了。

解决方案

如果我理解正确,所有现代浏览器都允许这样做。所以我在这里找到最好的解决方案。

解。



查看相关问题:




I've encountered the task to access parent window from iFrame, if the window in iFrame was loaded from another domain. If I understand correctly, all modern browsers do now allow to do this. So I'm here to find the best solution.

I'm going to accomplish this next way:

I have an overlay with an iFrame within it. This will work instead of pop-ups to prevent pop-up blockers to block my content. The task is to reload the main page when the document in the iFrame finishes some work. In a document, which will be loaded to an iFrame, I will add

<div id="is_closed" class="false"></div>

In a parent window I'll add function, which will be called every second and check if this div still has class name "false". When this will be changed to "true", I'll call some callbacks.

If you have any better solution, please share it with me. Will appreciate any help.

Edit: This is impossible because it's not only impossible to manipulate parent window from child window, but vice versa too. My idea was to manipulate child window from parent window. I was wrong.

解决方案

If I understand correctly, all modern browsers do now allow to do this. So I'm here to find the best solution.

This is your solution. What you're asking is not possible.

See related questions:

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

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