Ticket #8717 (closed bug: invalid)
IE error deleting iframes
| Reported by: | chris.a.broome@… | Owned by: | chris.a.broome@… |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | unfiled | Version: | 1.5.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I noticed a weird error deleting iframes in IE with jquery.
To note the frame was hidden via a "display:none", and was created dynamically off a click event.
The error was in the generic jQuery.each method starting on line 4853 of the development jquery file, specifically this snippet:
contents: function( elem ) {
return jQuery.nodeName( elem, "iframe" ) ?
elem.contentDocument || elem.contentWindow.document :
jQuery.makeArray( elem.childNodes );
}
After some investigation, it seems that in some cases the elem.contentDocument can be very problematic. Running a "typeof elem.contentDocument" produced "unknown" in IE, which quite frankly I didn't think was allowed. I guess that wrecked havoc on the whole "||" comparison.
I got this working with:
contents: function( elem ) {
var rv = null;
if( jQuery.nodeName(elem, "iframe")) {
if( typeof elem.contentDocument != 'unknown')
{
if(typeof elem.contentDocument != 'undefined' ) {
rv = elem.contentDocument;
}
else if(typeof elem.contentWindow != 'undefined' && typeof elem.contentWindow.document != 'undefined'){
rv = elem.contentWindow.document;
}
}
}
else {
rv = jQuery.makeArray(elem.childNodes);
}
return rv;
}
which isn't very clean, but worked.
Change History
comment:2 Changed 2 years ago by timmywil
- Owner set to chris.a.broome@…
- Status changed from new to pending
comment:3 Changed 2 years ago by chris.a.broome@…
- Status changed from pending to new
Okay, it may take me a bit to reproduce this outside of the larger project...
comment:4 Changed 2 years ago by chris.a.broome@…
Okay I found the suspect culprit: http://jsfiddle.net/rN2KM/2/
So it looks like the culprit is this snippet:
if ($.browser.msie){
photoHiddenIFrame.data("loadFix", setInterval(function() {
if ($.trim(photoHiddenIFrame.contents().html())) {
if (photoHiddenIFrame.data("loadFix")) clearInterval(photoHiddenIFrame.data("loadFix"));
photoHiddenIFrame.trigger('load');
}
}, 500));
}
Once you associate the data method to iframe with a setTimeout, or setInterval IE starts throwing the "unknown" typeof's. The original developer's not available right now, so I don't know if this was a bug fix of any kind.
comment:5 Changed 2 years ago by anonymous
In speaking with the original developer the setInterval loop was a means to check to see if the content of the iframe changed. If the "load" or "onreadystatechanged" event could be triggered in IE when the state of the frame changes, he could drop this workaround altogether.
In the live code, we're submitting images via form post to a dynamically created iframe. Then reading the success string from the frame.
comment:6 Changed 2 years ago by timmywil
- Priority changed from undecided to low
- Status changed from new to closed
- Resolution set to invalid
Checking ready state on an iframe is tricky. You can check using jQuery if the iframe is not cross-domain. If it helps, we do this in our test suite:
var interval = setInterval( function() {
if ( win && win.jQuery && win.jQuery.isReady ) {
clearInterval( interval );
// continue
start();
// call actual tests passing the correct jQuery isntance to use
fn.call( this, win.jQuery, win );
document.body.removeChild( iframe );
iframe = null;
}
}, 15 );
Regardless, this is not a bug in jQuery core, but a matter of the idiosyncracies with iframes in IE.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Seriously? You got an "unknown"? I didn't think that was possible either. Nevertheless, if you could provide a reduced test case on http://jsfiddle.net that replicates your issue, it would save us time. Thank you for submitting your bug!