Bug Tracker

Modify

Ticket #5683 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

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

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

comment:1 Changed 3 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 3 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 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to duplicate

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.