我有一个包含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内容是否已成功加载
发布评论