1

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.

J.Churchill
  • 430
  • 3
  • 12
Mart Blegger
  • 113
  • 2
  • 8

1 Answers1

4

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.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 1
    Thanks for the reply, but then I'm restricted to my own server: Origin X is not allowed by Access-Control-Allow-Origin – Mart Blegger May 02 '12 at 19:21