如何检查iframe是否加载失败? jQuery的? [英] How to check if iframe fails to load? jquery?

查看:2311
本文介绍了如何检查iframe是否加载失败? jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有这个jquery代码,它工作正常。当用户单击提交按钮时它会执行什么操作,它会隐藏表单,显示加载程序,然后将数据提交到链接并在iframe中加载输出。

I have this jquery code right now and it's working fine. What it does it when a user clicks the submit button, it would hide the form, show the loader, then submit the data to a link and load the output in an iframe.

$(document).ready(function() {

$("#xxx_form").validate({
    submitHandler: function() {
        $('#input_form').hide('slow');
        $('#loader').show('slow');
        form.submit();
    }
});

$("#xxx_frame").load(function (){
    $('#loader').hide('slow');
    $('#history').show('slow');
    $('#xxx_frame').show('slow');
});

});

这个工作正常。我需要的是如何检查iframe加载是否正常。在我测试期间,他们是iframe超时或者发出无法连接到服务器的错误的时间。由于ISP失败。现在我需要检查这种错误,我该怎么做?

This is working fine. What I need is how to check if the iframe loaded fine or not. During my testing their are times when the iframe would timeout or give an error that it can't connect to the server. Due to ISP failure. Now I need to check for this kind of errors, how can I do this?

推荐答案

据我所知,那里无法在iframe中测试错误。 .error() 活动但根据文档中的评论:

As far as I can see, there is no way to test for an error within an iframe. There is the .error() event but according to a comment in the documentation:


在iframe上使用.error()似乎永远不会触发(即使.load()将触发成功的iframe加载)。

Using .error() on an iframe never seems to trigger (even though .load() will trigger on a successful iframe load).

也许您需要使用自己实现某种超时.load() event:如果加载事件(表示成功)未在5秒内触发,则表示出错。

maybe you need to implement some kind of timeout yourself using the .load() event: If the load event (signifying success) doesn't fire within, say, five seconds, assume an error.

这篇关于如何检查iframe是否加载失败? jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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