How do I capture the HTTP code of an iframe?

↘锁芯ラ 提交于 2020-01-05 05:54:23

问题


I would like to catch the HTTP code of an iframe. Depending on the HTTP code the iframe must continue/stop loading. Is there any way to do this, using Jquery etc? Or should I use Curl first to check the HTTP code and then load the iframe?

Thanks in advance.


回答1:


You can do this by using XmlHttRequest to load your "iframe" :

var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
    if (httpRequest.readyState === 4) {
        if (httpRequest.status === 200) {
            // success
            document.getElementById('iframeId').innerHtml = httpRequest.responseText;
        } else {
            // failure. Act as you want 
        }
    }
};
httpRequest.open('GET', iframeContentUrl);
httpRequest.send();

No need to use jquery just for this.



来源:https://stackoverflow.com/questions/10418031/how-do-i-capture-the-http-code-of-an-iframe

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