Skip to main content

Bug Tracker

Side navigation

#8717 closed bug (invalid)

Opened March 30, 2011 09:52PM UTC

Closed March 31, 2011 03:35PM UTC

Last modified March 14, 2012 04:00PM UTC

IE error deleting iframes

Reported by: chris.a.broome@gmail.com Owned by: chris.a.broome@gmail.com
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.

Attachments (0)
Change History (6)

Changed March 30, 2011 10:21PM UTC by timmywil comment:1

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!

Changed March 31, 2011 12:05AM UTC by timmywil comment:2

owner: → chris.a.broome@gmail.com
status: newpending

Changed March 31, 2011 12:12AM UTC by chris.a.broome@gmail.com comment:3

status: pendingnew

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

Changed March 31, 2011 02:21PM UTC by chris.a.broome@gmail.com comment:4

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.

Changed March 31, 2011 03:07PM UTC by anonymous comment:5

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.

Changed March 31, 2011 03:35PM UTC by timmywil comment:6

_comment0: 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: \ <pre> \ var interval = setInterval( function() { \ if ( win && win.jQuery && win.jQuery.isReady ) { \ clearInterval( interval ); \ // call the callback \ fn.call( this, win.jQuery, win ); \ document.body.removeChild( iframe ); \ iframe = null; \ } \ }, 15 ); \ </pre> \ \ Regardless, this is not a bug in jQuery core, but a matter of the idiosyncracies with iframes in IE.1301585728104330
_comment1: 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 ); \ // call the callback \ 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.1301585786027149
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.