Bug Tracker

Opened 10 years ago

Closed 10 years ago

#5683 closed bug (duplicate)

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?

Change History (3)

comment:1 Changed 10 years ago by joelfinch

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 );

});

comment:2 Changed 10 years ago by joelfinch

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 );
	});

comment:3 Changed 10 years ago by dmethvin

Resolution: duplicate
Status: newclosed

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

Note: See TracTickets for help on using tickets.