Reputation: 113
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.
Upvotes: 1
Views: 4351
Reputation: 382150
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.
Upvotes: 4