Skip to main content

Bug Tracker

Side navigation

#5683 closed bug (duplicate)

Opened December 19, 2009 03:57PM UTC

Closed December 20, 2009 03:11AM UTC

onload fires before document.body exists, in dynamically written iframes in FF

Reported by: joelfinch Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

If an iframe's HTML is completely replaced via script (e.g. using document.write) the onload event for the re-written window can trigger immediately, before DOMContentLoaded, and more importantly, before document.body is created.

This causes a script error in jQuery's W3C Box Model test function, which expects document.body to exist when ready() is called.

The script error shows up when using Firefox 3.5.6, though the same error occurs in older versions also.

The problem seems to be dependent on file load times and caching, and occurs most frequently on intranet rather than internet connections. I think this is because of the speed of intranet responses.

Since window.onload doesn't technically make any claims about the availability of the DOM (and it's apparent that FF considers them as separate states), perhaps the fallback onload handler should check/wait for document.body before proceeding?

Attachments (0)
Change History (3)

Changed December 20, 2009 01:07AM UTC by joelfinch comment:1

A script snippet with a proposed fix:

// A fallback to window.onload, that will always work

jQuery.event.add( window, "load", function(){

if (document.body)

jQuery.ready()

else

setTimeout( arguments.callee, 0 );

});

Changed December 20, 2009 01:15AM UTC by joelfinch comment:2

Apologies, formatting fail. It should look like:

	// A fallback to window.onload, that will always work
	jQuery.event.add( window, "load", function(){
		if (document.body)
			jQuery.ready();
		else
			setTimeout( arguments.callee, 0 );
	});

Changed December 20, 2009 03:11AM UTC by dmethvin comment:3

resolution: → duplicate
status: newclosed

This is a dup of #4320, if the problem still exists in 1.4a2 please reopen that ticket.