Yablargo
Yablargo

Reputation: 3596

asynchronous Form w/ Iframe Target -- OnLoad works in FF, Chrome, IE9, doesn't get response in IE7

I have an ajax-style form in a popup window in my app. I use a form with a target iframe, then on the iframe.load() function, I take the contents and display them back into my popup.

This works on IE9, Chrome, Firefox:

 $("iframe[name=addpart-iframe]").load(function () {
            //FF and IE fire the load when the popup first load, chrome does not. This kips the first onload where no submit has happened yet
               if (firstLoad == true) {
                   firstLoad = false;
                   return;
               }


               var response = this.contentDocument.body.innerHTML;
               $("#AddForm").html(response);


           });       

This works great, except in IE7. When I look at this.contentDocument.body -- the debugger says that body is not a valid property. I look at the outer HTML, and my iframe is also empty at this time. Not sure why!

Upvotes: 1

Views: 1107

Answers (1)

Ram
Ram

Reputation: 144699

The contentDocument property refers to the document element inside the iframe (this is equivalent to contentWindow.document), but is not supported by Internet Explorer versions before IE8.

For earlier versions of IE before 8, you can use contentWindow property.

var response;

if (this.contentDocument) {
    response = this.contentDocument.body.innerHTML;
} else {
    response = this.contentWindow.document.body.innerHTML;
}

Upvotes: 2

Related Questions