检测iframe内容是否已成功加载

编程入门 行业动态 更新时间:2024-10-28 09:26:59
本文介绍了检测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内容是否已成功加载

本文发布于:2023-10-11 17:36:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1482371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   内容   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!