jQuery.error() is not working for iframe.

别说谁变了你拦得住时间么 提交于 2019-12-20 01:46:48

问题


I'm trying to use jquery to detect whether an iframe fails to load or the page doesn't exist, but the code below isn't working:

$('#frame').error(function(){
    //code here
});

回答1:


One of the comments on the documentation says:

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

This event does not appear to be designed to work in this use case.

The answers to this question explain how to do it.




回答2:


iframe do not trigger onerror event even if it fails to load the document. I think load will be triggered even in this case and you can check for the status code to determine if the page is loaded successfully or no.



来源:https://stackoverflow.com/questions/6867853/jquery-error-is-not-working-for-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!