跨域iframe内容负载检测 [英] Cross domain iframe content load detection

查看:91
本文介绍了跨域iframe内容负载检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的问题。我有一个父页面,将创建一个模式jquery对话框与iframe包含在对话框中。 iframe将填充来自第三方域的内容。我的问题是,我需要创建一些对话框级别的JavaScript,可以检测iframe的内容是否成功加载,如果它没有在5秒的时间框架内,然后关闭对话框并将用户返回到父页面。

I have a rather interesting problem. I have a parent page that will create a modal jquery dialog with an iframe contained within the dialog. The iframe will be populated with content from a 3rd party domain. My issue is that I need to create some dialog level javascript that can detect if the content of the iframe loaded successfully and if it hasn't within a 5 second time frame, then to close the dialog and return the user to the parent page.

我研究过许多解决方案,只有两个是真正的价值。

I have researched numerous solutions and only two are of any true value.


  1. 获取远程站点以包含document.domain ='our-domain.com'的javascript行。

  2. 使用URL Fragment黑客,但是我需要请求远程网站
    能够通过在网址末尾附加#some_value来修改网址,而且我的对话框窗口必须轮询网址,直到它看到或超时。

这些是老实说我唯一的选择吗?有没有更简单的方法来检测这个?

Are these honestly the only options I have to work with? Is there not a simpler way to just detect this?

我一直在研究是否有一种方法来轮询http响应错误,但这仍然限于相同的限制

I have been researching if there's a way to poll for http response errors, but this still remains confined to the same restrictions.

任何帮助都将非常感激。

Any help would be immensely appreciated.

感谢

推荐答案

最简单的方法(如果您可以将代码添加到外部网站)是让他们添加一个不可见的iframe指向您的域上的特殊html文件。然后可以使用 parent.parent.foo()通知原始窗口有关加载事件。

The easiest way (if you can get code added to the external sites) is to have them add an invisible iframe pointing to a special html file on your domain. This could then use parent.parent.foo() to notify the original window about the load event.

对于加载事件,只会告诉你窗口是否加载,不是加载的,或者如果文档已准备好进行交互。

Listening for the "load" event will only tell you if the window loaded, not what was loaded or if the document is ready for interaction.

这篇关于跨域iframe内容负载检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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