Ticket #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: | ||
| 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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

A script snippet with a proposed fix: