When, exactly, does onLoad occur
I am specifically concerned with the onload event for selected elements of the DOM. For the purpose of开发者_如何转开发 example assume there is an image in my DOM.
As I thought I understood it, the onload event for this image should fire when the image is drawn to the screen, but recently I've been given data to suggest otherwise. So my question is as follows:
When, in the order of the following events, does the onload event for an image fire?
- HTML containing the image is examined
- Request is made for the image
- First Byte is received for the image
- Last Byte is received
- Browser examines the header of the HTTP response
- Image is drawn to the screen
I am specifically concerned with Firefox, but I would also be interested in how this affects Internet Explorer (specifically IE8) and Chrome
The load event occurs after the image has been drawn on the screen.
Demo: http://jsfiddle.net/e5hvr/
(The alert blocks the browser thread, so if the image hadn't been drawn already, you wouldn't be able to see it while the alert is still open.)
Per the jQuery docs
While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received.
So, to answer your question, I would say after all of the events you listed.
I would say all but 6. And your events are in the wrong order, of course; the headers come before the data.
精彩评论