[英]How do I capture the HTTP code of an iframe?
我想抓住iframe的HTTP代码。 根据HTTP代码,iframe必须继续/停止加载。 有没有办法做到这一点,使用Jquery等? 或者我应该首先使用Curl检查HTTP代码,然后加载iframe?
提前致谢。
您可以使用XmlHttRequest加载“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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.