检测iframe内容是否已成功加载 [英] Detect if the iframe content has loaded successfully

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

问题描述

我有一个包含iframe的小部件。用户可以配置此iframe的网址,但如果无法加载网址(它不存在或用户无法访问互联网),则iframe应会故障转移到默认离线页面。

I have a widget that contains an iframe. The user can configure the url of this iframe, but if the url could not be loaded (it does not exists or the user does not have access to internet) then the iframe should failover to a default offline page.

问题是,如何检测iframe是否可以加载?我尝试订阅加载事件,并且,如果这个事件在一段时间后没有触发,那么我会进行故障切换,但这只能在Firefox中使用,因为IE和Chrome在找不到页面时触发加载事件

The question is, how can I detect if the iframe could be loaded or not? I tried subscribing to the 'load' event, and, if this event is not fired after some time then I failover, but this only works in Firefox, since IE and Chrome fires the 'load' event when the "Page Not Found" is displayed.

推荐答案

现在,浏览器有一系列的安全限制,让你远离iframe的内容't of your domain)。

Nowadays the browsers have a series of security limitations that keep you away from the content of an iframe (if it isn´t of your domain).

如果您确实需要该功能,则必须构建一个服务器页面,该页面必须作为代理运行,接收url作为参数,测试它是否为有效的网址,并执行重定向或显示错误页面。

If you really need that functionality, you have to build a server page that have to work as a proxy, that receive the url as a parameter, test if it is a valid url, and does the redirect or display the error page.

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

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