如何捕获iframe的HTTP代码? [英] How do I capture the HTTP code of an iframe?
本文介绍了如何捕获iframe的HTTP代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想抓住iframe的HTTP代码。根据HTTP代码,iframe必须继续/停止加载。有没有办法做到这一点,使用Jquery等?或者我应该首先使用Curl来检查HTTP代码,然后加载iframe?
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?
提前致谢。
推荐答案
您可以使用XmlHttRequest加载iframe来执行此操作:
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();
不需要为此使用jquery。
No need to use jquery just for this.
这篇关于如何捕获iframe的HTTP代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文