我想捕获 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。
关于javascript - 如何捕获 iframe 的 HTTP 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10418031/