Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#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:
Blocked by: Blocking:

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 (6)

comment:1 Changed 9 years ago by timmywil

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!

comment:2 Changed 9 years ago by timmywil

Owner: set to chris.a.broome@…
Status: newpending

comment:3 Changed 9 years ago by chris.a.broome@…

Status: pendingnew

Okay, it may take me a bit to reproduce this outside of the larger project...

comment:4 Changed 9 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 9 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 9 years ago by timmywil

Priority: undecidedlow
Resolution: invalid
Status: newclosed

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.

Last edited 9 years ago by timmywil (previous) (diff)
Note: See TracTickets for help on using tickets.